0
{
"id" : "25",
"authors" : 
    [
        {
            "firstname":"Ayn",
            "lastname":"Rand"
        },
        {
            "firstname":"Mark",
            "lastname" : "Twain"
        }
    ]
}

Here is my Java class:

public class FavoriteAuthors {
    public String id;
    public List<Author> authors;

    public static class Author {
        public String firstname;
        public String lastname;
    }
}

I have already tried using the following 2 approaches:

FavoriteAuthors favAuthors = Json.fromJson(json, FavoriteAuthors.class);

and

ObjectMapper objectMapper = new ObjectMapper();
FavoriteAuthors favAuthors = objectMapper.readValue(json, FavoriteAuthors.class);

In both the approaches, I receive the following exception:

(no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)

Could anyone please point me to the right approach here?

3
  • Like the error message says, you need to declare constructors for the class (or setters for the fields) . Commented Apr 14, 2021 at 6:00
  • I think you need to define the List like below in the pojo class. @SerializedName("authors") @Expose private List<Author> authors = null; Else you also check this link help you in convert online jsonschema2pojo.org Commented Apr 14, 2021 at 6:09
  • Stale question, the asker doesn't need the answer Commented Jul 26, 2021 at 15:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.