이 JSON 비트를 POJO로 가져 오는 데 문제가 있습니다. 여기 JSON 목록을 POJO로 변환
protected ThreadLocal<ObjectMapper> jparser = new ThreadLocal<ObjectMapper>();
public void receive(Object object) {
try {
if (object instanceof String && ((String)object).length() != 0) {
ObjectDefinition t = null ;
if (parserChoice==0) {
if (jparser.get()==null) {
jparser.set(new ObjectMapper());
}
t = jparser.get().readValue((String)object, ObjectDefinition.class);
}
Object key = t.getKey();
if (key == null)
return;
transaction.put(key,t);
}
} catch (Exception e) {
e.printStackTrace();
}
}
는 POJO로 전환 할 필요가있는 JSON이다 : 나는 잭슨은 다음과 같이 구성되어 사용하고
{
"id":"exampleID1",
"entities":{
"tags":[
{
"text":"textexample1",
"indices":[
2,
14
]
},
{
"text":"textexample2",
"indices":[
31,
36
]
},
{
"text":"textexample3",
"indices":[
37,
43
]
}
]
}
그리고 마지막으로, 여기에 내가 현재 자바 클래스에있는 내용은 다음과 같습니다
protected Entities entities;
@JsonIgnoreProperties(ignoreUnknown = true)
protected class Entities {
public Entities() {}
protected Tags tags;
@JsonIgnoreProperties(ignoreUnknown = true)
protected class Tags {
public Tags() {}
protected String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
};
public Tags getTags() {
return tags;
}
public void setTags(Tags tags) {
this.tags = tags;
}
};
//Getters & Setters ...
더 간단한 개체를 POJO로 변환 할 수 있었지만 그 목록은 저를 곤혹스럽게 만들었습니다.
도움을 주시면 감사하겠습니다. 감사!
http://stackoverflow.com/questions/9829403/deserialize-json-to-arraylistpojo-using-jackson – mre