1

Is it possible to "intercept" the unmarshalling process of JAXB?

I have an xml reponse that partially should be converted to a different java fields structure:

<xml>
  <X_FIELD1></X_FIELD1>
  <X_FIELD2></X_FIELD2>
  ... 
  <X_FIELD11></X_FIELD11>
</xml>

In my java class, I'd prefer to unmarshal this to a List<String>, instead of 11 String fields.

public class XmlResponse {
   private String X_FIELD1;
   private String X_FIELD2;
   //...
   private String X_FIELD11;

//   private List<String> xFields;
} 

But is that possible?

membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

0

You should use a custom xml adapter

http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html

http://docs.oracle.com/javaee/5/api/javax/xml/bind/annotation/adapters/XmlAdapter.html

apply it on the class level and implement the adapter.

Cris
  • 4,947
  • 6
  • 44
  • 73