Package net.sodacan.core.serialize.gson
Class GsonSerializer
java.lang.Object
net.sodacan.core.serialize.gson.GsonSerializer
- All Implemented Interfaces:
Serializer
Serialize and deserialize Actors and Messages to Json using Google's Gson.
We instantiate a pool of Gson instances during configuration so that the methods here can be called
safely from any thread/actor.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ActorId
protected ActorMetadata
protected GsonSerializerFactory
-
Constructor Summary
ConstructorsConstructorDescriptionGsonSerializer
(GsonSerializerFactory factory, ActorId actorId, ActorMetadata actorMetadata) -
Method Summary
Modifier and TypeMethodDescriptiondeserialize
(byte[] source) Deserialize a byte array into a new Message.void
deserialize
(byte[] source, Actor actor) To deserialize an Actor requires two steps.deserializeField
(byte[] source, Class<?> fieldClass) Deserialize the @Save fields of an Actor into an existing actor.byte[]
We are asked to serialize the fields of an actor, rather than the Actor as a whole.byte[]
Serialize a Message to a byte arraybyte[]
serializeField
(Object fieldValue) Serialize a field rather than a whole actor
-
Field Details
-
factory
-
actorMetadata
-
actorId
-
-
Constructor Details
-
GsonSerializer
-
-
Method Details
-
serializeField
Serialize a field rather than a whole actor- Specified by:
serializeField
in interfaceSerializer
- Parameters:
fieldValue
-- Returns:
- Byte array
-
deserializeField
Description copied from interface:Serializer
Deserialize the @Save fields of an Actor into an existing actor.- Specified by:
deserializeField
in interfaceSerializer
- Parameters:
source
-fieldClass
- Class of the field that we're returning- Returns:
- An object containing the field value
-
serialize
We are asked to serialize the fields of an actor, rather than the Actor as a whole. We serialize it as a map which is, in turn, taken care of in the MapAdapter- Specified by:
serialize
in interfaceSerializer
- Parameters:
actor
-- Returns:
-
deserialize
To deserialize an Actor requires two steps. First, deserialize a Map of the Actor's field values. Then populate the Actor's @Save fields from the deserialized Map.- Specified by:
deserialize
in interfaceSerializer
- Parameters:
source
-actor
-
-
serialize
Description copied from interface:Serializer
Serialize a Message to a byte array- Specified by:
serialize
in interfaceSerializer
- Parameters:
message
-- Returns:
-
deserialize
Description copied from interface:Serializer
Deserialize a byte array into a new Message.- Specified by:
deserialize
in interfaceSerializer
- Parameters:
source
-- Returns:
- A newly constructed Message
-