Package org.simpleframework.xml.core
Class PrimitiveValue
java.lang.Object
org.simpleframework.xml.core.PrimitiveValue
- All Implemented Interfaces:
Converter
The
PrimitiveValue
is used to serialize a primitive
value to and from a node. If a value name is provided in the
annotation then this will serialize and deserialize that value
with the given name, if the value is primitive and no name is
specified then the value is written inline, that is without any
enclosing XML element.
<entry key="one">example one</entry> <entry key="two">example two</entry> <entry key="three">example three</entry>Allowing the value to be written as either an XML element or an inline text value enables a more flexible means for representing the value. The only condition for having an inline value is that the key is specified as an attribute in the annotation.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Context
This is the context used to support the serialization process.private final Entry
The entry object contains the details on how to write the value.private final PrimitiveFactory
The primitive factory used to resolve the primitive to a string.private final Primitive
The primitive converter used to read the value from the node.private final Style
This is the style used to style the XML names for the value.private final Type
Represents the primitive type the value is serialized to and from. -
Constructor Summary
ConstructorsConstructorDescriptionPrimitiveValue
(Context context, Entry entry, Type type) Constructor for thePrimitiveValue
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate boolean
isOverridden
(OutputNode node, Object value) This is used to determine whether the specified value has been overridden by the strategy.This method is used to read the value value from the node.This method is used to read the value value from the node.private Object
readAttribute
(InputNode node, String name) This method is used to read the text value from the node.private Object
readElement
(InputNode node, String key) This method is used to read the element value from the node.boolean
This method is used to validate the value from the node.private boolean
validateAttribute
(InputNode node, String key) This method is used to validate the value from the node.private boolean
validateElement
(InputNode node, String key) This method is used to validate the value from the node.void
write
(OutputNode node, Object item) This method is used to write the value to the specified node.private void
writeAttribute
(OutputNode node, Object item, String key) This method is used to write the value to the specified node.private void
writeElement
(OutputNode node, Object item, String key) This method is used to write the value to the specified node.
-
Field Details
-
factory
The primitive factory used to resolve the primitive to a string. -
context
This is the context used to support the serialization process. -
root
The primitive converter used to read the value from the node. -
style
This is the style used to style the XML names for the value. -
entry
The entry object contains the details on how to write the value. -
type
Represents the primitive type the value is serialized to and from.
-
-
Constructor Details
-
PrimitiveValue
Constructor for thePrimitiveValue
object. This is used to create the value object which converts the map value to an instance of the value type. This can also resolve references.- Parameters:
context
- this is the context object used for serializationentry
- this is the entry object that describes entriestype
- this is the type that this converter deals with
-
-
Method Details
-
read
This method is used to read the value value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then an exception is thrown. -
read
This method is used to read the value value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then an exception is thrown. -
readElement
This method is used to read the element value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and returned.- Parameters:
node
- this is the node to read the value object fromkey
- this is the name of the value XML element- Returns:
- this returns the value deserialized from the node
- Throws:
Exception
-
readAttribute
This method is used to read the text value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and returned.- Parameters:
node
- this is the node to read the value object fromname
- this is the name of the value XML attribute, if any- Returns:
- this returns the value deserialized from the node
- Throws:
Exception
-
validate
This method is used to validate the value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and the node is valid. -
validateElement
This method is used to validate the value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and the node is valid.- Parameters:
node
- this is the node to read the value object fromkey
- this is the name of the node to be validated- Returns:
- this returns true if the primitive key is valid
- Throws:
Exception
-
validateAttribute
This method is used to validate the value from the node. The value read from the node is resolved using the template filter. If the value value can not be found according to the annotation attributes then null is assumed and the node is valid.- Parameters:
node
- this is the node to read the value object fromkey
- this is the name of the node to be validated- Returns:
- this returns true if the primitive key is valid
- Throws:
Exception
-
write
This method is used to write the value to the specified node. The value written to the node can be an attribute or an element depending on the annotation attribute values. This method will maintain references for serialized elements. -
writeElement
This method is used to write the value to the specified node. The value written to the node can be an attribute or an element depending on the annotation attribute values. This method will maintain references for serialized elements.- Parameters:
node
- this is the node that the value is written toitem
- this is the item that is to be writtenkey
- this is the name of the element to be created- Throws:
Exception
-
writeAttribute
This method is used to write the value to the specified node. The value written to the node can be an attribute or an element depending on the annotation attribute values. This method will maintain references for serialized elements.- Parameters:
node
- this is the node that the value is written toitem
- this is the item that is to be writtenkey
- this is the name of the attribute to be created- Throws:
Exception
-
isOverridden
This is used to determine whether the specified value has been overridden by the strategy. If the item has been overridden then no more serialization is require for that value, this is effectively telling the serialization process to stop writing.- Parameters:
node
- the node that a potential override is written tovalue
- this is the object instance to be serialized- Returns:
- returns true if the strategy overrides the object
- Throws:
Exception
-