Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSON / XML unmarshaller problem  RSS feed

Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm facing with following issue:

I'm trying to unmarshal the JSON data received from web server using this approach:

ClientResponse responseJ = server.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//Get the entity of the response
String textEntityJ = (String)responseJ.getEntity(String.class);

JSONJAXBContext contextJson = null;
JSONUnmarshaller unmarshallerJson = null;
MyClass myClassJson = null;

//built JSONConfiguration based on mapped notation
contextJson = new JSONJAXBContext(JSONConfiguration.natural().build(), MyClass.class);
unmarshallerJson = contextJson.createJSONUnmarshaller();//create JSON Unmarshaller

myClassJson = unmarshallerJson.unmarshalFromJSON(new StringReader(textEntityJ), MyClass.class);

Even I get the data in the 'textEntityJ' in the format {"version":["abb.123","xyz.456"]} the unmarshaller returns always MyClass object with empty List ( myClassJson.getVersion().size = 0).

MyClass structure:

@XmlType(name = "", propOrder = {
@XmlRootElement(name = "versions")
public class MyClass {

protected List<String> version;

public List<String> getVersion() {
if (version == null) {
version = new ArrayList<String>();
return this.version;


What could be wrong? The same issue I'm facing with XML approach. I receive data (as String) in the XML format, but unmarshaller failes in case when Java bean contains LIST object.

Thanks in advance for your help,
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!