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?

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

0 Answers0