解决Spring MVC 3转换JSON封装的数据时提示JsonMappingException Unrecognized field ‘fieldname’, not marked as ignorable


最近在做一个SpringMVC类型的项目,利用SpringDemo中的mvc-ajax工程,直接把服务器端json处理部分拿过来用,在处理包含了数组对象的JSP页面是提示JsonMappingException Unrecognized field ‘fieldname’, not marked as ignorable

Google了一番,发现需要设置一个objectMapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);属性即可解决这个问题。

找到JacksonConversionServiceConfigurer类,修改
jsonConverter.setObjectMapper(new ConversionServiceAwareObjectMapper(this.conversionService));

ObjectMapper objectMapper = new ConversionServiceAwareObjectMapper(this.conversionService);
objectMapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonConverter.setObjectMapper(objectMapper);

问题完美解决,服务器端的Bean对象已经能够正常拿到客户端提交的数组。

参考 :RestTemplate, not marked as ignorable

Advertisements

解决Spring MVC 3转换JSON封装的数据时提示JsonMappingException Unrecognized field ‘fieldname’, not marked as ignorable》上有1条评论

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s