发送JSON请求时出现问题

时间:2015-07-29 17:35:41

标签: json rest jersey jackson jax-rs

当我以JSON格式发送REST请求时,我遇到了一个问题。当调用服务时,一些参数会被遗漏。但是当我以xml格式发送请求时,它工作正常。我是一个问题geting抛出错误:

SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "create_session_param"

对象映射器类如下所示:

objectMapper = new ObjectMapper();
        objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);

        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,true);

        JaxbAnnotationModule module = new JaxbAnnotationModule();
        // maintain JAXB annotation support
        objectMapper.registerModule(module);

有人可以帮我解决这个问题吗?

感谢。

1 个答案:

答案 0 :(得分:1)

您只有WRAP_ROOT_VALUE用于序列化。请记住序列化是POJO到JSON。 SerializationFeature.WRAP_ROOT_VALUE是在创建JSON时实际添加 "create_session_param"的那个。

我们需要JSON到POJO,它是反序列化,它有自己的功能集。在这种情况下,我们需要一个功能 un 包装JSON中的根值。为此,有

  

DeserializationFeature.UNWRAP_ROOT_VALUE

所以

mapper.configure(DeserializationFeature UNWRAP_ROOT_VALUE, true);
相关问题