@Retention(RUNTIME)
public @interface ElementMap
ElementMap
annotation represents a method or field
that is a Map
for storing key value pairs. The map
object deserialized is typically of the same type as the field.
However, a class
attribute can be used to override the
field type, however the type must be assignable.
<map class="java.util.HashMap"> <entry key="one">value one</entry> <entry key="two">value two</entry> <entry key="three">value three</entry> </map>If a
class
attribute is not provided and the type or
the field or method is abstract, a suitable match is searched for
from the maps available from the Java collections framework. This
annotation can support both primitive and composite values and
keys enabling just about any configuration to be used.
<map class="java.util.HashMap"> <entry key="1"> <value>value one</value> </entry> <entry key="2"> <value>value two</value> </entry> <entry key="3"> <value>value three</value> </entry> </map>The above XML is an example of the output for an composite value object. Composite and primitive values can be used without any specified attributes, in such a case names for primitives are the names of the objects they represent. Also, if desired these default names can be overridden using the provided attributes making the resulting XML entirely configurable.
Modifier and Type | Optional Element | Description |
---|---|---|
boolean |
attribute |
Represents whether the key value is to be an attribute or an
element.
|
boolean |
data |
This is used to determine whether the element data is written
in a CDATA block or not.
|
boolean |
empty |
This is used to determine if an optional field or method can
remain null if it does not exist.
|
java.lang.String |
entry |
This is used to provide a the name of the entry XML element
that wraps the key and value elements.
|
boolean |
inline |
Determines whether the element list is inlined with respect
to the parent XML element.
|
java.lang.String |
key |
This is used to provide a key XML element for each of the
keys within the map.
|
java.lang.Class |
keyType |
Represents the type of key the element map contains.
|
java.lang.String |
name |
This represents the name of the XML element.
|
boolean |
required |
Determines whether the element is required within the XML
document.
|
java.lang.String |
value |
This is used to provide a value XML element for each of the
values within the map.
|
java.lang.Class |
valueType |
Represents the type of value the element map contains.
|
java.lang.String name
java.lang.String entry
java.lang.String value
java.lang.String key
java.lang.Class keyType
class
attribute value for the map. If
this is not specified then the type can be determined from the
generic parameter of the annotated Map
object.java.lang.Class valueType
class
attribute value for the map. If
this is not specified then the type can be determined from the
generic parameter of the annotated Map
object.boolean attribute
java.util.Date
or a string could be
represented as an attribute key for the generated XML.boolean required
boolean data
boolean inline
boolean empty