I'm trying to create a POJO with the given Jackson String:
String json ={"name" : [{"John" , "Mark"}]};
ObjectMapper mapper = new ObjectMapper();
Students students = mapper.readValue(json, Students.class);
public class Students {
String[] name;
public Students (String[] name) (
this.name = name;
}
But I'm getting this error:
"No Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)"
CodePudding user response:
try this
public static void main(String[] args) throws JsonProcessingException {
String json = "{\"name\" : [\"John\" , \"Mark\"]}";
ObjectMapper mapper = new ObjectMapper();
Students students = mapper.readValue(json, Students.class);
}
public static class Students {
private String[] name;
public Students() {
}
public Students(String[] name) {
this.name = name;
}
public String[] getName() {
return name;
}
}
- your json input is wrong : [{"John" , "Mark"}] -> ["John" , "Mark"]
- Add a default constructor