I am trying to parse a JSON using Jackson,here is my class
@JsonIgnoreProperties(ignoreUnknown = true)
public class Customer {
private String name;
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
}
and the runner class
public class jsontoObj {
public static void main(String args[]) throws IOException {
ObjectMapper mapper = new ObjectMapper();
String json = "{\n" +
" \"customer\":\n" +
" {\n" +
" \"name\": \"John Doeyy\"\n" +
" }\n" +
"}";
Customer customer = mapper.readValue( json, Customer.class);
System.out.println(customer.getName());
}
}
the setName
method is working but getting null
in customer.getName()
.
I don't want to use moxy