我是Spring MVC REST的新手。我花了数小时搜索并尝试不同的方法来解决这个问题。 这段代码为什么不用双引号产生JSON?postForEntity不会产生正确的JSON表示...在我的智慧结尾
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mappingJacksonHttpMessageConverter.setObjectMapper(objectMapper);
mappingJacksonHttpMessageConverter.setPrettyPrint(true);
converters.add(mappingJacksonHttpMessageConverter);
template.setMessageConverters(converters);
ResponseEntity<EAApplication> response = template.postForEntity(
LOCAL_URI,
requestEntity, EAApplication.class);
产生下面的JSON没有双引号,所以服务器发送400错误的请求。
{ applications:
[ { submissionDate: '2014-09-05T08:28:17',
firstName: 'Mickey',
lastName: 'Mouse',
email: '[email protected]',
dietaryRestrictions: 'Cheese only',
restSkillLevel: 'Novice',
jsonSchemaSkillLevel: 'Expert',
restStandardFamiliarity: true,
slimFamiliarity: true,
odataLibFamiliarity: true } ] }
我们可以看到你的'requestEntity'吗? – 2014-09-06 17:24:30