Package org.simpleframework.xml.convert
Class AnnotationStrategy
- java.lang.Object
-
- org.simpleframework.xml.convert.AnnotationStrategy
-
- All Implemented Interfaces:
Strategy
public class AnnotationStrategy extends java.lang.Object implements Strategy
TheAnnotationStrategy
object is used to intercept the serialization process and delegate to custom converters. This strategy uses theConvert
annotation to specify the converter to use for serialization and deserialization. If there is no annotation present on the field or method representing the object instance to be serialized then this acts as a transparent proxy to an internal strategy.By default the
TreeStrategy
is used to perform the normal serialization process should there be no annotation specifying a converter to use. However, any implementation can be used, including theCycleStrategy
, which handles cycles in the object graph. To specify the internal strategy to use it can be provided in the constructor.- See Also:
TreeStrategy
-
-
Field Summary
Fields Modifier and Type Field Description private ConverterScanner
scanner
This is used to scan for an annotation and create a converter.private Strategy
strategy
This is the strategy that is delegated to for serialization.
-
Constructor Summary
Constructors Constructor Description AnnotationStrategy()
Constructor for theAnnotationStrategy
object.AnnotationStrategy(Strategy strategy)
Constructor for theAnnotationStrategy
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
isReference(Value value)
This is used to determine if theValue
provided represents a reference.Value
read(Type type, NodeMap<InputNode> node, java.util.Map map)
This is used to read theValue
which will be used to represent the deserialized object.private Value
read(Type type, NodeMap<InputNode> node, Value value)
This is used to read theValue
which will be used to represent the deserialized object.private boolean
write(Type type, java.lang.Object value, NodeMap<OutputNode> node)
This is used to serialize a representation of the object value provided.boolean
write(Type type, java.lang.Object value, NodeMap<OutputNode> node, java.util.Map map)
This is used to serialize a representation of the object value provided.
-
-
-
Field Detail
-
scanner
private final ConverterScanner scanner
This is used to scan for an annotation and create a converter.
-
strategy
private final Strategy strategy
This is the strategy that is delegated to for serialization.
-
-
Constructor Detail
-
AnnotationStrategy
public AnnotationStrategy()
Constructor for theAnnotationStrategy
object. This creates a strategy that intercepts serialization on any annotated method or field. If no annotation exists then this delegates to an internalTreeStrategy
object.
-
AnnotationStrategy
public AnnotationStrategy(Strategy strategy)
Constructor for theAnnotationStrategy
object. This creates a strategy that intercepts serialization on any annotated method or field. If no annotation exists then this will delegate to theStrategy
provided.- Parameters:
strategy
- the internal strategy to delegate to
-
-
Method Detail
-
read
public Value read(Type type, NodeMap<InputNode> node, java.util.Map map) throws java.lang.Exception
This is used to read theValue
which will be used to represent the deserialized object. If there is an annotation present then the value will contain an object instance. If it does not then it is up to the internal strategy to determine what the returned value contains.- Specified by:
read
in interfaceStrategy
- Parameters:
type
- this is the type that represents a method or fieldnode
- this is the node representing the XML elementmap
- this is the session map that contain variables- Returns:
- the value representing the deserialized value
- Throws:
java.lang.Exception
- thrown if the class cannot be resolved
-
read
private Value read(Type type, NodeMap<InputNode> node, Value value) throws java.lang.Exception
This is used to read theValue
which will be used to represent the deserialized object. If there is an annotation present then the value will contain an object instance. If it does not then it is up to the internal strategy to determine what the returned value contains.- Parameters:
type
- this is the type that represents a method or fieldnode
- this is the node representing the XML elementvalue
- this is the value from the internal strategy- Returns:
- the value representing the deserialized value
- Throws:
java.lang.Exception
-
write
public boolean write(Type type, java.lang.Object value, NodeMap<OutputNode> node, java.util.Map map) throws java.lang.Exception
This is used to serialize a representation of the object value provided. If there is aConvert
annotation present on the provided type then this will use the converter specified to serialize a representation of the object. If however there is no annotation then this will delegate to the internal strategy. This returns true if the serialization has completed.- Specified by:
write
in interfaceStrategy
- Parameters:
type
- this is the type that represents the field or methodvalue
- this is the object instance to be serializednode
- this is the XML element to be serialized tomap
- this is the session map used by the serializer- Returns:
- this returns true if it was serialized, false otherwise
- Throws:
java.lang.Exception
- thrown if the details cannot be set
-
write
private boolean write(Type type, java.lang.Object value, NodeMap<OutputNode> node) throws java.lang.Exception
This is used to serialize a representation of the object value provided. If there is aConvert
annotation present on the provided type then this will use the converter specified to serialize a representation of the object. If however there is no annotation then this will delegate to the internal strategy. This returns true if the serialization has completed.- Parameters:
type
- this is the type that represents the field or methodvalue
- this is the object instance to be serializednode
- this is the XML element to be serialized to- Returns:
- this returns true if it was serialized, false otherwise
- Throws:
java.lang.Exception
-
isReference
private boolean isReference(Value value)
This is used to determine if theValue
provided represents a reference. If it does represent a reference then this will return true, if it does not then this returns false.- Parameters:
value
- this is the value instance to be evaluated- Returns:
- this returns true if the value represents a reference
-
-