All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gsonpath.AutoGsonAdapterFactory Maven / Gradle / Ivy

Go to download

An annotation processor which generates Type Adapters for the Google Gson library

There is a newer version: 4.0.0
Show newest version
package gsonpath;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * An interface annotated with this annotation will automatically generate a Gson {@link com.google.gson.TypeAdapterFactory}
 * at compile time.
 * 

* This annotation exists to ensure developers are able to use GsonPath within multiple libraries/modules without any * interface name collisions (assuming the developer uses unique factory interface names, or package structures) *

* An example of how to use the annotation is as follows: *

 *
 * {@literal @}AutoGsonAdapterFactory
 *  public interface ProjectTypeAdapterFactory extends TypeAdapterFactory {
 *  {
 *  }
 * 
*

* This will then generated a concrete implementation of the {@link com.google.gson.TypeAdapterFactory} that should be * used when constructing the {@link com.google.gson.Gson} object. An example of how to do this is as follows: *

 *
 *  Gson gson = new GsonBuilder()
 *                  registerTypeAdapterFactory(GsonPath.createTypeAdapterFactory(ProjectTypeAdapterFactory.class));
 *                  .build();
 * 
* The above usage will use reflection to find the concrete implementation. If you wish to reference the class directly * to avoid adding an entry to proguard, you may use the following alternative: *
 *
 *  Gson gson = new GsonBuilder()
 *                  registerTypeAdapterFactory(new ProjectTypeAdapterFactoryImpl());
 *                  .build();
 * 
* Be aware that the ProjectTypeAdapterFactoryImpl class will not exist until the annotation processor has executed. *

* Note: This is a mandatory annotation if any usages of the {@link AutoGsonAdapter} are found. * The annotation processor will throw a compilation error if there is no interfaces annotated with this, or if there * is more than one interface per project. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) public @interface AutoGsonAdapterFactory { }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy