congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
GsonBuilder.registerTypeAdapterFactory
Code IndexAdd Tabnine to your IDE (free)

How to use
registerTypeAdapterFactory
method
in
com.google.gson.GsonBuilder

Best Java code snippets using com.google.gson.GsonBuilder.registerTypeAdapterFactory (Showing top 20 results out of 936)

origin: stackoverflow.com

 GsonBuilder b = new GsonBuilder();
...
b.registerTypeAdapterFactory(HibernateProxyTypeAdapter.FACTORY);
...
Gson gson = b.create();
origin: stackoverflow.com

public class GsonUtils {
 private static final GsonBuilder gsonBuilder = new GsonBuilder()
     .setPrettyPrinting();
 public static void registerType(
     RuntimeTypeAdapterFactory<?> adapter) {
   gsonBuilder.registerTypeAdapterFactory(adapter);
 }
 public static Gson getGson() {
   return gsonBuilder.create();
 }
origin: immutables/immutables

private static Gson createGson() {
 GsonBuilder gsonBuilder = new GsonBuilder();
 // there are no longer auto-registed from class-path, but from here or if added manually.
 gsonBuilder.registerTypeAdapterFactory(new TypeAdapters());
 for (TypeAdapterFactory factory : ServiceLoader.load(TypeAdapterFactory.class)) {
  gsonBuilder.registerTypeAdapterFactory(factory);
 }
 return gsonBuilder.create();
}
origin: immutables/immutables

/**
 * the fully configured gson instance.
 * @return the gson instanse
 */
@Value.Default
public Gson gson() {
 GsonBuilder gsonBuilder = new GsonBuilder();
 for (TypeAdapterFactory factory : ServiceLoader.load(TypeAdapterFactory.class)) {
  gsonBuilder.registerTypeAdapterFactory(factory);
 }
 return gsonBuilder.create();
}
origin: MovingBlocks/Terasology

private static Gson createGsonForModules() {
  return new GsonBuilder()
      .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
      .registerTypeAdapterFactory(new UriTypeAdapterFactory())
      .setPrettyPrinting().create();
}
origin: MovingBlocks/Terasology

public TextureInfoFormat() {
  super("texinfo");
  gson = new GsonBuilder().registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory()).create();
}
origin: apache/incubator-gobblin

 public static <T> Gson getGson(Class<T> clazz) {
  Gson gson = new GsonBuilder().registerTypeAdapterFactory(new GsonInterfaceAdapter(clazz)).create();
  return gson;
 }
}
origin: MovingBlocks/Terasology

private static Gson createGson() {
  return new GsonBuilder()
      .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
      .registerTypeAdapterFactory(new UriTypeAdapterFactory())
      .registerTypeAdapter(Version.class, new VersionTypeAdapter())
      .registerTypeAdapter(Name.class, new NameTypeAdapter())
      .setPrettyPrinting()
      .create();
}
origin: MovingBlocks/Terasology

public BlockFamilyDefinitionFormat(AssetManager assetManager) {
  super("block");
  this.assetManager = assetManager;
  gson = new GsonBuilder()
      .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
      .registerTypeAdapterFactory(new AssetTypeAdapterFactory(assetManager))
      .registerTypeAdapter(BlockFamilyDefinitionData.class, new BlockFamilyDefinitionDataHandler())
      .registerTypeAdapter(Vector3f.class, new Vector3fTypeAdapter())
      .registerTypeAdapter(Vector4f.class, new Vector4fTypeAdapter())
      .registerTypeAdapter(Class.class, new BlockFamilyHandler())
      .create();
}
origin: MovingBlocks/Terasology

/**
 * Create a {@link GsonBuilder} which uses type handlers loaded from the given
 * {@link TypeSerializationLibrary} and complies with Terasology JSON serialization rules.
 *
 * @param typeSerializationLibrary The {@link TypeSerializationLibrary} to load type handler
 *                                 definitions from
 */
public static GsonBuilder createGsonBuilderWithTypeSerializationLibrary(TypeSerializationLibrary typeSerializationLibrary) {
  TypeAdapterFactory typeAdapterFactory =
      new GsonTypeSerializationLibraryAdapterFactory(typeSerializationLibrary);
  return createDefaultGsonBuilder()
      .registerTypeAdapterFactory(typeAdapterFactory);
}
origin: immutables/immutables

 private static Gson createGson() {
  GsonBuilder gsonBuilder = new GsonBuilder();
  for (TypeAdapterFactory factory : ServiceLoader.load(TypeAdapterFactory.class)) {
   gsonBuilder.registerTypeAdapterFactory(factory);
  }
  return gsonBuilder.create();
 }
}
origin: MovingBlocks/Terasology

public UISkinFormat() {
  super("skin");
  gson = new GsonBuilder()
    .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
    .registerTypeAdapter(Font.class, new AssetTypeAdapter<>(Font.class))
    .registerTypeAdapter(UISkinData.class, new UISkinTypeAdapter())
    .registerTypeAdapter(TextureRegion.class, new TextureRegionTypeAdapter())
    .registerTypeAdapterFactory(new GsonTypeHandlerAdapterFactory() {
      {
        addTypeHandler(Color.class, new ColorTypeHandler());
      }
    })
    .registerTypeAdapter(Optional.class, new OptionalTextureRegionTypeAdapter())
    .create();
}
origin: MovingBlocks/Terasology

protected static Gson createGson() {
  return new GsonBuilder()
      .registerTypeAdapter(Name.class, new NameTypeAdapter())
      .registerTypeAdapter(Version.class, new VersionTypeAdapter())
      .registerTypeAdapter(BindsConfig.class, new BindsConfig.Handler())
      .registerTypeAdapter(SetMultimap.class, new SetMultimapTypeAdapter<>(Input.class))
      .registerTypeAdapter(SecurityConfig.class, new SecurityConfig.Handler())
      .registerTypeAdapter(Input.class, new InputHandler())
      .registerTypeAdapter(Resolution.class, new ResolutionHandler())
      //.registerTypeAdapter(UniverseConfig.class, new UniverseConfig.Handler())
      .registerTypeAdapter(PixelFormat.class, new PixelFormatHandler())
      .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
      .registerTypeAdapterFactory(new UriTypeAdapterFactory())
      .setPrettyPrinting().create();
}
origin: runelite/runelite

  public static Gson build()
  {
    RuntimeTypeAdapterFactory<WebsocketMessage> typeAdapter = RuntimeTypeAdapterFactory.of(WebsocketMessage.class)
      .registerSubtype(Handshake.class)
      .registerSubtype(LoginResponse.class)
      .registerSubtype(Ping.class);

    return new GsonBuilder()
      .registerTypeAdapterFactory(typeAdapter)
      .create();
  }
}
origin: immutables/immutables

private static com.google.gson.Gson createGson() {
 GsonBuilder gson = new GsonBuilder();
 // this one is no longer auto-registered
 gson.registerTypeAdapterFactory(new TypeAdapters());
 for (TypeAdapterFactory factory : ServiceLoader.load(TypeAdapterFactory.class)) {
  gson.registerTypeAdapterFactory(factory);
 }
 // register custom serializer for polymorphic Holder
 final HolderJsonSerializer custom = new HolderJsonSerializer();
 gson.registerTypeAdapter(Holder.class, custom);
 gson.registerTypeAdapter(ImmutableHolder.class, custom);
 return gson.create();
}
origin: kairosdb/kairosdb

@Inject
public QueryParser(FeatureProcessor processingChain, QueryPluginFactory pluginFactory)
{
  m_processingChain = processingChain;
  m_pluginFactory = pluginFactory;
  m_descriptorMap = new HashMap<>();
  GsonBuilder gsonBuilder = new GsonBuilder();
  gsonBuilder.registerTypeAdapterFactory(new LowercaseEnumTypeAdapterFactory());
  gsonBuilder.registerTypeAdapter(TimeUnit.class, new TimeUnitDeserializer());
  gsonBuilder.registerTypeAdapter(TrimAggregator.Trim.class, new TrimDeserializer());
  gsonBuilder.registerTypeAdapter(FilterAggregator.FilterOperation.class, new FilterOperationDeserializer());
  gsonBuilder.registerTypeAdapter(DateTimeZone.class, new DateTimeZoneDeserializer());
  gsonBuilder.registerTypeAdapter(Metric.class, new MetricDeserializer());
  gsonBuilder.registerTypeAdapter(SetMultimap.class, new SetMultimapDeserializer());
  gsonBuilder.registerTypeAdapter(RelativeTime.class, new RelativeTimeSerializer());
  gsonBuilder.registerTypeAdapter(SetMultimap.class, new SetMultimapSerializer());
  gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
  m_gson = gsonBuilder.create();
}
origin: MovingBlocks/Terasology

  /**
   * Create a {@link GsonBuilder} which uses the given type handlers and complies with Terasology
   * JSON serialization rules.
   *
   * @param typeHandlerEntries The type handlers to use during serialization.
   */
  @SuppressWarnings("unchecked")
  public static GsonBuilder createGsonBuilderWithTypeHandlers(TypeHandlerEntry<?>... typeHandlerEntries) {
    GsonTypeHandlerAdapterFactory typeAdapterFactory = new GsonTypeHandlerAdapterFactory();

    for (TypeHandlerEntry typeHandlerEntry : typeHandlerEntries) {
      typeAdapterFactory.addTypeHandler(typeHandlerEntry);
    }

    return createDefaultGsonBuilder()
        .registerTypeAdapterFactory(typeAdapterFactory);
  }
}
origin: MovingBlocks/Terasology

public UIData load(JsonElement element, Locale otherLocale) throws IOException {
  NUIManager nuiManager = CoreRegistry.get(NUIManager.class);
  TranslationSystem translationSystem = CoreRegistry.get(TranslationSystem.class);
  TypeSerializationLibrary library = new TypeSerializationLibrary(CoreRegistry.get(TypeSerializationLibrary.class));
  library.add(UISkin.class, new AssetTypeHandler<>(UISkin.class));
  library.add(Border.class, new BorderTypeHandler());
  GsonBuilder gsonBuilder = new GsonBuilder()
      .registerTypeAdapterFactory(new GsonTypeSerializationLibraryAdapterFactory(library))
      .registerTypeAdapterFactory(new CaseInsensitiveEnumTypeAdapterFactory())
      .registerTypeAdapter(UIData.class, new UIDataTypeAdapter())
      .registerTypeHierarchyAdapter(UIWidget.class, new UIWidgetTypeAdapter(nuiManager));
  // override the String TypeAdapter from the serialization library
  gsonBuilder.registerTypeAdapter(String.class, new I18nStringTypeAdapter(translationSystem, otherLocale));
  Gson gson = gsonBuilder.create();
  return gson.fromJson(element, UIData.class);
}
origin: immutables/immutables

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
 MongoDatabase db = mock(MongoDatabase.class);
 MongoCollection<Entity> collection = mock(MongoCollection.class);
 when(db.getCollection(anyString(), any(Class.class))).thenReturn(collection);
 when(collection.withCodecRegistry(any(CodecRegistry.class))).thenReturn(collection);
 RepositorySetup setup = RepositorySetup.builder().database(db)
     .executor(MoreExecutors.newDirectExecutorService())
     .gson(new GsonBuilder().registerTypeAdapterFactory(new GsonAdaptersEntity()).create())
     .build();
 this.repository = new EntityRepository(setup);
 FindIterable<Entity> iterable = mock(FindIterable.class);
 when(collection.find(any(Bson.class))).thenReturn(iterable);
 MongoCursor<Entity> cursor = mock(MongoCursor.class);
 when(iterable.iterator()).thenReturn(cursor);
 this.cursor = cursor;
}
origin: immutables/immutables

 public static void main(String... args) {
  MongoClient client = new MongoClient("localhost");
  RepositorySetup setup = RepositorySetup.builder()
    .database(client.getDatabase("test"))
    .executor(MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()))
    .gson(new GsonBuilder()
      .registerTypeAdapterFactory(new GsonAdaptersEnt())
      .create())
    .build();

  EntRepository repository = new EntRepository(setup);

  EntRepository.Criteria where = repository.criteria()
    .uuid("8b7a881c-6ccb-4ada-8f6a-60cc99e6aa20")
    .actionIn("BAN", "IPBAN");

  Criteria or = where.expiresAbsent()
    .or()
    .with(where)
    .expiresGreaterThan(TimeInstant.of(1467364749679L));

  System.out.println(or);

  repository.find(or).fetchAll().getUnchecked();
 }
}
com.google.gsonGsonBuilderregisterTypeAdapterFactory

Javadoc

Register a factory for type adapters. Registering a factory is useful when the type adapter needs to be configured based on the type of the field being processed. Gson is designed to handle a large number of factories, so you should consider registering them to be at par with registering an individual type adapter.

Popular methods of GsonBuilder

  • create
    Creates a Gson instance based on the current configuration. This method is free of side-effects to t
  • <init>
    Constructs a GsonBuilder instance from a Gson instance. The newly constructed GsonBuilder has the sa
  • registerTypeAdapter
  • setPrettyPrinting
    Configures Gson to output Json that fits in a page for pretty printing. This option only affects Jso
  • serializeNulls
    Configure Gson to serialize null fields. By default, Gson omits all fields that are null during seri
  • disableHtmlEscaping
    By default, Gson escapes HTML characters such as < > etc. Use this option to configure Gson to pass-
  • setDateFormat
    Configures Gson to serialize Date objects according to the pattern provided. You can call this metho
  • setFieldNamingPolicy
    Configures Gson to apply a specific naming policy to an object's field during serialization and dese
  • registerTypeHierarchyAdapter
  • excludeFieldsWithoutExposeAnnotation
    Configures Gson to exclude all fields from consideration for serialization or deserialization that d
  • setExclusionStrategies
    Configures Gson to apply a set of exclusion strategies during both serialization and deserialization
  • enableComplexMapKeySerialization
    Enabling this feature will only change the serialized form if the map key is a complex type (i.e. no
  • setExclusionStrategies,
  • enableComplexMapKeySerialization,
  • setLenient,
  • addSerializationExclusionStrategy,
  • excludeFieldsWithModifiers,
  • serializeSpecialFloatingPointValues,
  • setVersion,
  • setFieldNamingStrategy,
  • addTypeAdaptersForDate

Popular in Java

  • Reactive rest calls using spring rest template
  • getResourceAsStream (ClassLoader)
  • getSupportFragmentManager (FragmentActivity)
  • getExternalFilesDir (Context)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • ServerSocket (java.net)
    This class represents a server-side socket that waits for incoming client connections. A ServerSocke
  • Path (java.nio.file)
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now