tags:

views:

63

answers:

2

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?

A: 

As 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.

secmask
A: 

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

Mapping your favorite class

JBoss Built-in JAXB Providers

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.

richj