问题描述
我绑定一个JSON响应使用杰克逊我的课。当有比我的类定义我的JSON响应更多的领域,除了一切的伟大工程。我想杰克逊忽略不我JSON响应存在的字段。这是由于兼容为将来的版本。如果我添加一个新的领域,我不希望我的客户previous版本崩溃。
想法?
ObjectMapper映射器=新ObjectMapper(); //可以重用,全球共享
PromoResponse promoResponse = mapper.readValue(R,PromoResponse.class);
您可以把 @JsonIgnoreProperties(ignoreUnknown = TRUE)
注释您PromoResponse类。
I am binding a JSON response to my class using Jackson. Everything works great except when there are more fields in my JSON response than my class defines. I want Jackson to ignore the fields that do not exist in my JSON response. This is due to compatability for future versions. If I add a new field I do not want previous versions of my client to crash.
Ideas?
ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
PromoResponse promoResponse = mapper.readValue(r, PromoResponse.class);
You can put the @JsonIgnoreProperties(ignoreUnknown=true)
annotation on your PromoResponse class.
这篇关于Java的杰克逊组织。codehaus.jackson.map.exc.UnrecognizedPropertyException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!