发送 JSON 请求时出现问题

Issue while Sending JSON Request

我在 JSON 中发送 REST 请求时遇到问题 format.Some 参数在调用 service.However 时丢失,当我发送xml format.The 问题中的请求抛出了以下错误:

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"

对象映射器 class 如下所示:

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);

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

谢谢。

您只有 WRAP_ROOT_VALUE 用于序列化。记住 序列化 是 JSON 的 POJO。 SerializationFeature.WRAP_ROOT_VALUE 是在创建 JSON.

时实际上 添加 "create_session_param" 的那个

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

DeserializationFeature.UNWRAP_ROOT_VALUE

也一样

mapper.configure(DeserializationFeature UNWRAP_ROOT_VALUE, true);