T
- Generic type template for extending classes.
User: Thomas Ginter
Date: 8/15/14
Time: 11:54public class LeoInheritanceGsonAdapter<T> extends Object implements com.google.gson.JsonSerializer<T>, com.google.gson.JsonDeserializer<T>
Constructor and Description |
---|
LeoInheritanceGsonAdapter() |
Modifier and Type | Method and Description |
---|---|
T |
deserialize(com.google.gson.JsonElement json,
Type typeOfT,
com.google.gson.JsonDeserializationContext context)
Gson invokes this call-back method during deserialization when it encounters a field of the
specified type.
|
com.google.gson.JsonElement |
serialize(T src,
Type typeOfSrc,
com.google.gson.JsonSerializationContext context)
Gson invokes this call-back method during serialization when it encounters a field of the
specified type.
|
public T deserialize(com.google.gson.JsonElement json, Type typeOfT, com.google.gson.JsonDeserializationContext context) throws com.google.gson.JsonParseException
In the implementation of this call-back method, you should consider invoking
JsonDeserializationContext.deserialize(com.google.gson.JsonElement, java.lang.reflect.Type)
method to create objects
for any non-trivial field of the returned object. However, you should never invoke it on the
the same type passing json
since that will cause an infinite loop (Gson will call your
call-back method again).
deserialize
in interface com.google.gson.JsonDeserializer<T>
json
- The Json data being deserializedtypeOfT
- The type of the Object to deserialize tocontext
- T
com.google.gson.JsonParseException
- if json is not in the expected format of typeofT
public com.google.gson.JsonElement serialize(T src, Type typeOfSrc, com.google.gson.JsonSerializationContext context)
In the implementation of this call-back method, you should consider invoking
JsonSerializationContext.serialize(Object, java.lang.reflect.Type)
method to create JsonElements for any
non-trivial field of the src
object. However, you should never invoke it on the
src
object itself since that will cause an infinite loop (Gson will call your
call-back method again).
serialize
in interface com.google.gson.JsonSerializer<T>
src
- the object that needs to be converted to Json.typeOfSrc
- the actual type (fully genericized version) of the source object.context
- Copyright © 2018 Department of Veterans Affairs. All Rights Reserved.