简体   繁体   中英

Unable to parse a json field class using Jackson jar

I have a json response :

"site":[  
               {  
                  "href":"https:www.abc.com",
                  "class":"child"
               }
]

I am trying to parse the response using the jackson jars in Java. I cant create a field class(as its a keyword) in my POJO to map this field. I tried class_ and _class but that returns org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "class" as it searches for the field class in my POJO Site.java How can such scenarios be handled?

Your property name in your POJO cannot be name "class", but you can specify to Jackson to use the property name "class" with the annotation.

@JsonProperty("class")
private String clazz;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM