Say I have this JSON example:
{
"title" : "tttt",
"custom" : {
"a" : "aaaaa",
"b" : "bbbbb",
"c" : {
"d" : "dddd"
}
}
}
I want to deserialize this into the following class:
public class Article {
private String title;
private String custom;
public void setTitle(String title) { this.title = title; }
public String getTitle() { return title; }
public void setCustom(String custom) { this.custom = custom; }
public String getCustom() { return custom; }
}
The result I want is for the title to be deserialized as per normal but the json subtree under "custom" to be not deserialized and set as the raw json string:
ObjectMapper mapper = new ObjectMapper();
Article article = mapper.readValue(content, Article.class);
assertEquals(article.getTitle(), "tttt");
assertEquals(article.getCustom(),
"{\"a\" : \"aaaaa\"," +
"\"b\" : \"bbbbb\"," +
"\"c\" : {" +
"\"d\" : \"dddd\" " +
"}" +
"}");
One other important note is that I can't change the original JSON under the custom node to use escaped json so it will be treated as a string.