Package org.eclipse.mosaic.lib.gson
Class TypeFieldTypeAdapter<T>
java.lang.Object
com.google.gson.TypeAdapter<T>
org.eclipse.mosaic.lib.gson.TypeFieldTypeAdapter<T>
- Type Parameters:
T
- the base type of which objects are created during deserialization
- Direct Known Subclasses:
GeoAreaAdapterFactory.GeoAreaAdapter
,PackageSpecificTypeAdapter
public abstract class TypeFieldTypeAdapter<T>
extends com.google.gson.TypeAdapter<T>
A type adapter which creates an object of a specific type based on a hidden "type" field.
An implementation of this abstract class must specify which type name translates to which target class.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TypeFieldTypeAdapter
(com.google.gson.TypeAdapterFactory parentFactory, com.google.gson.Gson gson) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
By default, a missing "type" field in the input JSON string leads to an error.protected abstract Class<?>
fromTypeName
(String type) Translates the name of the type to the class to deserialize.read
(com.google.gson.stream.JsonReader in) protected abstract String
toTypeName
(Class<?> typeClass) Translates the class of the object to serialize to an unambiguous type name.void
Methods inherited from class com.google.gson.TypeAdapter
fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree
-
Constructor Details
-
TypeFieldTypeAdapter
protected TypeFieldTypeAdapter(com.google.gson.TypeAdapterFactory parentFactory, com.google.gson.Gson gson)
-
-
Method Details
-
allowNullType
protected void allowNullType()By default, a missing "type" field in the input JSON string leads to an error. By calling this method any proceeding deserialization processes allow this missing field by passingnull
tofromTypeName(java.lang.String)
instead of throwing an exception. -
fromTypeName
Translates the name of the type to the class to deserialize.- Parameters:
type
- the name of the type- Returns:
- the class associated with the type
-
toTypeName
Translates the class of the object to serialize to an unambiguous type name.- Parameters:
typeClass
- the class to serialize- Returns:
- the type name which is associated with the class to serialize
-
read
- Specified by:
read
in classcom.google.gson.TypeAdapter<T>
-
write
- Specified by:
write
in classcom.google.gson.TypeAdapter<T>
- Throws:
IOException
-