[Simple-support] ElementMap, ElementList using interface
Brought to you by:
niallg
|
From: Jochen v. W. <Jo...@va...> - 2012-11-30 19:15:43
|
Hi,
I have this set of custom classes:
PLBigDecimal, PLBoolean, PLData, PLDate, PLNumber, PLString: these all
implement the interface PLObject
PLKey (does not implement interface PLObject).
@ElementMap(name = "dict",
key = "key", keyType = PLKey.*class*,
required = *false*, inline = *false*)
*private*Map<PLKey, PLObject> plDictionary;
The XML looks like this:
<?_xml_ version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<date>2012-11-30T10:14:00Z</date>
_<dict>_
<key>key01</key><string>value01</string>
<key>key02</key><string>value02</string>
<key>key03</key><string>value03</string>
_</dict>_
<real>150.0</real>
<integer>500</integer>
<string>myPLString</string>
<true/>
<false/>
_</plist>_
How can I parse the <dict> structure.
My current (see above) annotation gives me this error:
Cannot instantiate interface PLObject for interface PLObject
How can I use this Map<PLKey, PLObject> so that it can hold any
combination of PLKey and my PLObject interface (PLString, PLBigDecimal,
...)?
Can this be done at all with simpleXML?
Any help on the map topic is appreciated!
The second thing:
@Element(name = "true", required = *false*)
@Convert(PLBooleanConverter.*class*)
*private*PLBoolean _plTrue_;
@Element(name = "false", required = *false*)
@Convert(PLBooleanConverter.*class*)
*private*PLBoolean _plFalse_;
Is it possible to bind two xml elements to one object?
The above works but I am looking for something like (map two xml tags to
one object):
@ElementUnion({
@Element(name = "false", required = *false*),
@Element(name = "true", required = *false*)
})
@Convert(PLBooleanConverter.*class*)
*private*PLBoolean _plBoolean_;
Thanks
Jochen
PS: Implementation for my root xml element, The ElementList is not
working for the same reason (interface cannot be instantiated)
@Root(name = "plist")
*public**class*PropertyList{
@ElementMap(name = "dict",
key = "key", keyType = PLKey.*class*,
required = *false*, inline = *false*)
*private*Map<PLKey, PLObject> plDictionary;
@ElementList(name = "array", required = *false*)
*private*List<PLObject> plArray;
@Element(name = "real", required = *false*)
@Convert(PLNumberConverter.*class*)
*private*PLNumber plReal;
@Element(name = "integer", required = *false*)
@Convert(PLNumberConverter.*class*)
*private*PLNumber plInteger;
@Element(name = "string", required = *false*)
@Convert(PLStringConverter.*class*)
*private*PLString plString;
@Element(name = "data", required = *false*)
@Convert(PLDataConverter.*class*)
*private*PLData plData;
@Element(name = "date", required = *false*)
@Convert(PLDateConverter.*class*)
*private*PLDate plDate;
@Element(name = "true", required = *false*)
@Convert(PLBooleanConverter.*class*)
*private*PLBoolean _plTrue_;
@Element(name = "false", required = *false*)
@Convert(PLBooleanConverter.*class*)
*private*PLBoolean _plFalse_;
@Attribute(required = *true*)
*private*String version;
*public*PropertyList(){
*super*();
}
}
|