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 ActorIdprotected ActorMetadataprotected 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.voiddeserialize(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:
serializeFieldin interfaceSerializer- Parameters:
fieldValue-- Returns:
- Byte array
-
deserializeField
Description copied from interface:SerializerDeserialize the @Save fields of an Actor into an existing actor.- Specified by:
deserializeFieldin 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:
serializein 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:
deserializein interfaceSerializer- Parameters:
source-actor-
-
serialize
Description copied from interface:SerializerSerialize a Message to a byte array- Specified by:
serializein interfaceSerializer- Parameters:
message-- Returns:
-
deserialize
Description copied from interface:SerializerDeserialize a byte array into a new Message.- Specified by:
deserializein interfaceSerializer- Parameters:
source-- Returns:
- A newly constructed Message
-