Package org.eclipse.mosaic.lib.util.gson
Class PackageSpecificTypeAdapter<T>
java.lang.Object
com.google.gson.TypeAdapter<T>
org.eclipse.mosaic.lib.gson.TypeFieldTypeAdapter<T>
org.eclipse.mosaic.lib.util.gson.PackageSpecificTypeAdapter<T>
This
TypeAdapterFactory
allows to create an object from JSON definition
based on a "type" attribute. According to the value of the value in the "type" attribute,
a class is loaded and an object of this class is instantiated. Since this explicitly works
with simple class names only, a search space of possible packages need to be defined, which
are used to resolve the actual class.-
Constructor Summary
ConstructorsConstructorDescriptionPackageSpecificTypeAdapter
(com.google.gson.TypeAdapterFactory parentFactory, com.google.gson.Gson gson) -
Method Summary
Modifier and TypeMethodDescriptionprotected Class<?>
fromTypeName
(String type) Translates the name of the type to the class to deserialize.searchInPackage
(Package searchPackage) Adds the given package to the search space.searchInPackage
(String packageName) Adds the given fully qualified package name to the search space.searchInPackageOfClass
(Class<?> clazz) Adds the package of the given class to the search space.protected String
toTypeName
(Class<?> typeClass) Translates the class of the object to serialize to an unambiguous type name.withClassLoader
(ClassLoader classLoader) Defines a specific class loader from which the searched classes are loaded.Methods inherited from class org.eclipse.mosaic.lib.gson.TypeFieldTypeAdapter
allowNullType, read, write
Methods inherited from class com.google.gson.TypeAdapter
fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree
-
Constructor Details
-
PackageSpecificTypeAdapter
public PackageSpecificTypeAdapter(com.google.gson.TypeAdapterFactory parentFactory, com.google.gson.Gson gson)
-
-
Method Details
-
searchInPackageOfClass
Adds the package of the given class to the search space. All classes within this package are candidates to be loaded by a given type name. -
searchInPackage
Adds the given package to the search space. All classes within this package are candidates to be loaded by a given type name. -
searchInPackage
Adds the given fully qualified package name to the search space. All classes within the given package are candidates to be loaded by a given type name. -
withClassLoader
Defines a specific class loader from which the searched classes are loaded. -
fromTypeName
Description copied from class:TypeFieldTypeAdapter
Translates the name of the type to the class to deserialize.- Specified by:
fromTypeName
in classTypeFieldTypeAdapter<T>
- Parameters:
type
- the name of the type- Returns:
- the class associated with the type
-
toTypeName
Description copied from class:TypeFieldTypeAdapter
Translates the class of the object to serialize to an unambiguous type name.- Specified by:
toTypeName
in classTypeFieldTypeAdapter<T>
- Parameters:
typeClass
- the class to serialize- Returns:
- the type name which is associated with the class to serialize
-