I have a generic (POJO-)container to share statistical data with clients:
@XmlRootElement
public class StatsSeries implements Serializable {
private TreeMap<Date, Number> timeSeries;
/* accessor methods */
}
Depending on the data, the server stores Long, Integer or Double in it, which is why I'm using abstract java.lang.Number.
Marshalling works fine, and hints indicating the concrete class are included in the data:
"timeSeries": {
"entry": [
{
"key": "2012-08-20T00:00:00Z",
"value": {
"$": "24",
"@type": "xs:long"
}
},
....
]
}
Or in XML representation:
<timeSeries>
<entry>
<key>2012-08-20T00:00:00Z</key>
<value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:long">24</value>
</entry>
...
</timeSeries>
When attempting to unmarshall this, I get an javax.xml.bind.UnmarshalException: Unable to create an instance of java.lang.Number.
I saw this question, but it doesn't help me. How can I annotate java.lang.Number? Any other suggestions?
Update: Looking at JAXB-890, I understand that it should be fixed either on JDK 1.7 or using com.sun.xml.bind:jaxb-impl:2.2.6 -- neither works for me.