我正在尝试使用杰克逊解析JSON,这是我的类
@JsonIgnoreProperties(ignoreUnknown = true)
public class Customer {
private String name;
public void setName(String n) {
name = n;
}
public String getName() {
return name;
}
}
和跑步者类
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());
}
}
setName
方法有效,但customer.getName()
null
。 我不想使用 moxy
根据您的映射,正确的 json 将是
String json = "{ "name": "John Doeyy" }";
我删除了嵌入的"客户"对象