user1558274
user1558274

Reputation: 39

Deserializing Composite Objects in Java

I have a question regarding deserializing composite objects. My object looks as follows:

public class Outside
{
   private String str1;
   private Inside s;
}

public class Inside
{
   private String str2;
   public Inside(String str2) 
   {
    this.field1 = str2;
   }
}

when I want to deserialize the response to Json

Outside o = wr.accept(MediaType.APPLICATION_JSON_TYPE).get(Outside .class);

I get the following exception ....ClientHandlerException: A message body reader for Java class Outside, and Java type class Outside, and MIME media type application/json was not found

I'm not sure what I'm doing wrong.

Upvotes: 1

Views: 544

Answers (1)

Nate W.
Nate W.

Reputation: 9249

java.lang.NoSuchMethodException: ....Inside.()

This is referring to a constructor of the form Inside(), which you don't have - you've only got Inside(String). Serialization requires a no-argument constructor so it can easily use reflection to instantiate your object, and then fill in the fields.

Thus, you need to add a no-arg constructor.

Upvotes: 2

Related Questions