org.qi4j.api.value
Interface ValueSerializer

All Known Subinterfaces:
OrgJsonValueSerializationService, ValueSerialization
All Known Implementing Classes:
OrgJsonValueSerialization, OrgJsonValueSerializer, ValueSerializerAdapter

public interface ValueSerializer

Use a ValueSerializer to serialize values state.

Serialized object must be one of:

Nested plain values, EntityReferences, Iterables, Maps, ValueComposites and EntityComposites are supported. EntityComposites and EntityReferences are serialized as their identity string.

Plain values can be one of:

Values of unknown types and all arrays are considered as Serializable and by so are serialized to base64 encoded bytes using pure Java serialization. If it happens that the value is not Serializable, a ValueSerializationException is thrown.

Having type information in the serialized payload allows to keep actual ValueComposite types and by so circumvent AmbiguousTypeException when deserializing.


Method Summary
<T> Function<T,java.lang.String>
serialize()
          Factory method for a serialize function.
<T> Function<T,java.lang.String>
serialize(boolean includeTypeInfo)
          Factory method for a serialize function.
 java.lang.String serialize(java.lang.Object object)
          Serialize the state of a value with type information.
 java.lang.String serialize(java.lang.Object object, boolean includeTypeInfo)
          Serialize the state of a value.
 void serialize(java.lang.Object object, java.io.OutputStream output)
          Serialize the state of a value with type information.
 void serialize(java.lang.Object object, java.io.OutputStream output, boolean includeTypeInfo)
          Serialize the state of a value.
 

Method Detail

serialize

<T> Function<T,java.lang.String> serialize()
Factory method for a serialize function.

Type Parameters:
T - the parametrized function input type
Returns:
a serialization function.

serialize

<T> Function<T,java.lang.String> serialize(boolean includeTypeInfo)
Factory method for a serialize function.

Type Parameters:
T - the parametrized function input type
Parameters:
includeTypeInfo - if type information should be included in the output
Returns:
a serialization function.

serialize

java.lang.String serialize(java.lang.Object object)
                           throws ValueSerializationException
Serialize the state of a value with type information.

Parameters:
object - an Object to serialize
Returns:
the state
Throws:
ValueSerializationException - if the Value serialization failed

serialize

java.lang.String serialize(java.lang.Object object,
                           boolean includeTypeInfo)
                           throws ValueSerializationException
Serialize the state of a value.

Parameters:
object - an Object to serialize
includeTypeInfo - if type information should be included in the output
Returns:
the state
Throws:
ValueSerializationException - if the Value serialization failed

serialize

void serialize(java.lang.Object object,
               java.io.OutputStream output)
               throws ValueSerializationException
Serialize the state of a value with type information.

Parameters:
object - an Object to serialize
output - that will be used as output
Throws:
ValueSerializationException - if the Value serialization failed

serialize

void serialize(java.lang.Object object,
               java.io.OutputStream output,
               boolean includeTypeInfo)
               throws ValueSerializationException
Serialize the state of a value.

Parameters:
object - an Object to serialize
output - that will be used as output
includeTypeInfo - if type information should be included in the output
Throws:
ValueSerializationException - if the Value serialization failed