How to ignore attribute when mapping to json from a text file to a Java object using Jackson? -
this question has answer here:
i have text file 'input.txt' contains text
{ "product" : { "name" : "pro-1", "category" : "a" } } and class
public class product { @jsonproperty("name") public string name; @jsonproperty("category") public string category ... ... } i using jackson
product p = mapper.readvalue(new file("input.txt"), product.class); my class has no attribute named "product" , result exception occurs when mapping json text product object. so, proper way ignore "product" attribute when mapping product object text file?
try this.
public class outerclass{ @jsonproperty("product") public product product; } outerclass outerobject = mapper.readvalue(new file("input.txt"), outerclass.class); then can use outerobject.product
Comments
Post a Comment