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

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

Best Java code snippets using com.google.gson.GsonBuilder.registerTypeAdapter (Showing top 20 results out of 3,690)

Refine searchRefine arrow

  • GsonBuilder.create
  • GsonBuilder.<init>
  • Gson.fromJson
origin: skylot/jadx

  private static <T> void populate(GsonBuilder builder, String json, Class<T> type, final T into) {
    builder.registerTypeAdapter(type, (InstanceCreator<T>) t -> into)
        .create()
        .fromJson(json, type);
  }
}
origin: elasticjob/elastic-job-lite

/**
 * 注册Gson解析对象.
 * 
 * @param type Gson解析对象类型
 * @param typeAdapter Gson解析对象适配器
 */
public static synchronized void registerTypeAdapter(final Type type, final TypeAdapter typeAdapter) {
  GSON_BUILDER.registerTypeAdapter(type, typeAdapter);
  gson = GSON_BUILDER.create();
}

origin: jphp-group/jphp

public static GsonBuilder createGsonBuilder(MemorySerializer memorySerializer) {
  GsonBuilder builder = new GsonBuilder();
  builder.registerTypeAdapter(Memory.class, memorySerializer);
  builder.registerTypeAdapter(NullMemory.class, memorySerializer);
  builder.registerTypeAdapter(UndefinedMemory.class, memorySerializer);
  builder.registerTypeAdapter(ReferenceMemory.class, memorySerializer);
  builder.registerTypeAdapter(TrueMemory.class, memorySerializer);
  builder.registerTypeAdapter(FalseMemory.class, memorySerializer);
  builder.registerTypeAdapter(LongMemory.class, memorySerializer);
  builder.registerTypeAdapter(DoubleMemory.class, memorySerializer);
  builder.registerTypeAdapter(ObjectMemory.class, memorySerializer);
  builder.registerTypeAdapter(ArrayMemory.class, memorySerializer);
  builder.registerTypeAdapter(BinaryMemory.class, memorySerializer);
  builder.registerTypeAdapter(CharMemory.class, memorySerializer);
  builder.registerTypeAdapter(KeyValueMemory.class, memorySerializer);
  builder.registerTypeAdapter(StringBuilderMemory.class, memorySerializer);
  builder.registerTypeAdapter(StringMemory.class, memorySerializer);
  return builder;
}
origin: stackoverflow.com

 GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(VkAudioAlbumsResponse.class, new VkAudioAlbumsResponseDeserializer());
Gson gson = gsonBuilder.create();
Response response = gson.fromJson(jsonString, Response.class);
origin: stackoverflow.com

 ...
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Location.class, new LocationDeserializer());
gsonBuilder.registerTypeAdapter(Location.class, new LocationSerializer());
Gson gson = gsonBuilder.create(); 
...
origin: stackoverflow.com

 GsonBuilder builder = new GsonBuilder();
builder.registerTypeAdapter(CityList.class, new CityListDeserializer());
Gson gson = builder.setFieldNamingPolicy(LOWER_CASE_WITH_UNDERSCORES).create();
CityList list = gson.fromJson(json, CityList.class);
origin: stackoverflow.com

 GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(MyBaseTypeModel.class, new MyTypeModelDeserializer());
Gson gson = gsonBuilder.create();

MyBaseTypeModel myTypeModel = gson.fromJson(myJsonString, MyBaseTypeModel.class);
origin: stackoverflow.com

 GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Object.class, new NaturalDeserializer());
Gson gson = gsonBuilder.create();
origin: jphp-group/jphp

public static GsonBuilder createGsonBuilderForDecode(MemoryDeserializer memoryDeserializer){
  GsonBuilder builder = new GsonBuilder();
  builder.registerTypeAdapter(Memory.class, memoryDeserializer);
  return builder;
}
origin: gocd/gocd

public GsonCodec(GsonBuilder builder) {
  // here we can register extra configurations, policies, adapters
  builder.registerTypeAdapter(CRMaterial.class, new MaterialTypeAdapter());
  builder.registerTypeAdapter(CRTask.class, new TaskTypeAdapter());
  builder.registerTypeAdapter(CRArtifact.class, new ArtifactTypeAdapter());
  gson = builder.create();
}
origin: stackoverflow.com

String jsonVal0 = "{\"id\": 5382, \"user\": \"Mary\" }";
 String jsonVal1 = "{\"id\": 2341, \"person\": \"Bob\"}";
 final GsonBuilder gsonBuilder = new GsonBuilder();
 gsonBuilder.registerTypeAdapter(MyClass.class, new MyClassTypeAdapter());
 final Gson gson = gsonBuilder.create();
 MyClass myClassInstance0 = gson.fromJson(jsonVal0, MyClass.class);
 MyClass myClassInstance1 = gson.fromJson(jsonVal1, MyClass.class);
 System.out.println("jsonVal0 :" + gson.toJson(myClassInstance0));
 // output: jsonVal0 :{"id":5382,"name":"Mary"}
 System.out.println("jsonVal1 :" + gson.toJson(myClassInstance1));
 // output: jsonVal1 :{"id":2341,"name":"Bob"}
origin: MovingBlocks/Terasology

public JsonBlockShapeLoader() {
  super("shape");
  gson = new GsonBuilder()
      .setPrettyPrinting()
      .registerTypeAdapter(BlockShapeData.class, new BlockShapeHandler())
      .registerTypeAdapter(BlockMeshPart.class, new BlockMeshPartHandler())
      .registerTypeAdapter(Vector3f.class, new Vector3fTypeAdapter())
      .registerTypeAdapter(Vector2f.class, new Vector2fTypeAdapter())
      .create();
}
origin: EngineHub/WorldEdit

/**
 * Create a standard {@link GsonBuilder} for WorldEdit.
 *
 * @return a builder
 */
public static GsonBuilder createBuilder() {
  GsonBuilder gsonBuilder = new GsonBuilder();
  gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter());
  gsonBuilder.registerTypeAdapter(BlockVector3.class, new BlockVectorAdapter());
  return gsonBuilder;
}
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 MaterialFormat(AssetManager assetManager) {
  super("mat");
  this.gson = new GsonBuilder().registerTypeAdapter(MaterialMetadata.class, new MaterialMetadataHandler()).create();
  this.assetManager = assetManager;
}
origin: stackoverflow.com

 public String messagesToJson(List<Message> messages) {  
  GsonBuilder gsonBuilder = new GsonBuilder();
  Gson gson = gsonBuilder.registerTypeAdapter(Message.class, new MessageAdapter()).create();
  return gson.toJson(messages);
}
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

public AtlasFormat(AssetManager assetManager) {
  super("atlas");
  this.assetManager = assetManager;
  gson = new GsonBuilder().registerTypeAdapter(Vector2i.class, new Vector2iTypeAdapter()).create();
}
origin: MovingBlocks/Terasology

@Before
public void init() {
  constructCalled.clear();
  destructCalled.clear();
  executeCalled.clear();
  nextId2 = 1;
  gsonBuilder = new GsonBuilder();
  BehaviorTreeBuilder builder = new BehaviorTreeBuilder() {
    @Override
    public BehaviorNode createNode(BehaviorNode node) {
      return new CountDelegate(node);
    }
  };
  gsonBuilder.registerTypeAdapter(BehaviorNode.class, builder);
  //        gsonBuilder.registerTypeAdapter(Action.class, new InheritanceAdapter<Action>("delay", Delay.class));
}
origin: stackoverflow.com

 public class Test {

public static void main(String[] args) {
  IAnimal animals[] = new IAnimal[]{new Cat("Kitty"), new Dog("Brutus", 5)};
  Gson gsonExt = null;
  {
    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(IAnimal.class   , new IAnimalAdapter());
    gsonExt = builder.create();
  }
  for (IAnimal animal : animals) {
    String animalJson = gsonExt.toJson(animal, IAnimal.class);
    System.out.println("serialized with the custom serializer:"  +animalJson);
    IAnimal animal2 = gsonExt.fromJson(animalJson, IAnimal.class);
    System.out.println(animal2.sound());
  }
}
com.google.gsonGsonBuilderregisterTypeAdapter

Javadoc

Configures Gson for custom serialization or deserialization. This method combines the registration of an TypeAdapter, InstanceCreator, JsonSerializer, and a JsonDeserializer. It is best used when a single object typeAdapter implements all the required interfaces for custom serialization with Gson. If a type adapter was previously registered for the specified type, it is overwritten.

This registers the type specified and no other types: you must manually register related types! For example, applications registering boolean.class should also register Boolean.class.

Popular methods of GsonBuilder

  • create
    Creates a Gson instance based on the current configuration. This method is free of side-effects to t
  • <init>
    Creates a GsonBuilder instance that can be used to build Gson with various configuration settings. G
  • 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
  • registerTypeAdapterFactory
    Register a factory for type adapters. Registering a factory is useful when the type adapter needs to
  • setFieldNamingPolicy
    Configures Gson to apply a specific naming policy to an object's field during serialization and dese
  • registerTypeHierarchyAdapter
    Configures Gson for custom serialization or deserialization for an inheritance type hierarchy. This
  • 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

  • Start an intent from android
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • getExternalFilesDir (Context)
  • Menu (java.awt)
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • URLEncoder (java.net)
    This class is used to encode a string using the format required by application/x-www-form-urlencoded
  • Deque (java.util)
    A linear collection that supports element insertion and removal at both ends. The name deque is shor
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JFileChooser (javax.swing)
  • Best plugins for Eclipse
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