I am trying to marshal/unmarshal a Map<String, Map<String, Serializable>>
via JAXB. There are two problems:
1. JAXB cannot handle complex maps.
2. JAXB cannot handle interfaces (Serializable in this context).
How is one supposed to get that through JAXB?
views:
63answers:
2As I know, XML doesn't support Map type. So you can try using like this
<item key="somekey" value="hello" />
but you need to check duplicate key yourself.
I think the main problem is the interface as JAXB ought to be able to marshal Map<String, ConcreteType>. The problem with interfaces is that JAXB demarshalling does not know what concrete type to use to implement the interface. The marshalling stream may not have come from Java code, so the stream can't contain the concrete type information. JAXB would have to choose an implementation, and it needs help to do that.
JAXB: How should I marshall complex nested data structures
This is a common problem with Web Services marshalling. One robust method is to use Data Transfer Objects containing concrete types that can be precisely defined in WSDL for the data transfer. You have to map your domain objects into and out of these DTOs in your application code, which is a disadvantage. One benefit of this approach is that your application is loosely coupled to the data transfer format.