CopaServer
Change of Plan Application
 All Classes Functions Pages
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
unicopa.copa.base.com.serialization.Serializer Class Reference

A serializer to serialize/deserialize objects in a way used by the system using GSON. More...

Inheritance diagram for unicopa.copa.base.com.serialization.Serializer:
Inheritance graph
Collaboration diagram for unicopa.copa.base.com.serialization.Serializer:
Collaboration graph

Static Public Member Functions

static String serialize (Object object)
 

Static Protected Member Functions

static Object deserialize (String json, String...packagePrefixes) throws APIException
 Deserialize a JSON string to produce an expected object of a class known to the system. More...
 

Static Protected Attributes

static final JsonParser parser = new JsonParser()
 
static final Gson gson
 

Detailed Description

A serializer to serialize/deserialize objects in a way used by the system using GSON.

Note that standard GSON serialization is used to convert an instance to JSON for all types where no type adapter is registered. If special treatment is needed, it has to be added to this class.

Author
Felix Wiemuth

Member Function Documentation

static Object unicopa.copa.base.com.serialization.Serializer.deserialize ( String  json,
String...  packagePrefixes 
) throws APIException
staticprotected

Deserialize a JSON string to produce an expected object of a class known to the system.

After API specification, the JSON object should have the form {"type":"TYPE","data":JSON} where TYPE is the simple class name of the java object represented and JSON is the standard JSON serialization of this object.

Parameters
json
packagePrefixesthe fully qualified package names of the allowed packages to look for the type specified in parameter "type" with "." concatenated
Returns
the deserialized object of type TYPE equivalent to the JSON representation
Exceptions
APIExceptionif the string is not a JSON object, not of the expected form or the class specified by TYPE cannot be found in the given packages

Member Data Documentation

final Gson unicopa.copa.base.com.serialization.Serializer.gson
staticprotected
Initial value:
= new GsonBuilder()
.registerTypeAdapter(RequestNotPracticableException.class,
new SimpleExceptionSerializer())
.registerTypeAdapter(RequestNotPracticableException.class,
new RequestNotPracticableExceptionDeserializer())
.registerTypeAdapter(InternalErrorException.class,
new SimpleExceptionSerializer())
.registerTypeAdapter(InternalErrorException.class,
new InternalErrorExceptionDeserializer())
.registerTypeAdapter(APIException.class,
new SimpleExceptionSerializer())
.registerTypeAdapter(APIException.class,
new APIExceptionDeserializer())
.registerTypeAdapter(PermissionException.class,
new SimpleExceptionSerializer())
.registerTypeAdapter(PermissionException.class,
new PermissionExceptionDeserializer())
.registerTypeAdapter(Date.class, new DateSerializer())
.registerTypeAdapter(Date.class, new DateDeserializer()).create()

The documentation for this class was generated from the following file: