繁体   English   中英

帖子数据中的Spring Resttemplate意外字段“会话”

[英]Spring Resttemplate unexpected field “session” in the post data

{
    "platform": "iOS",
    "device": {
        "os_name": "iPhone OS",
        "manufacturer": "Apple",
        "type": "iPhone3",
        "version": "1",
        "os_version": "5.1.1"
    },
    "app_version": "1.0",
    "device_id": "",
    "app_key": "1234567890",
    "developer_key": "",
    "app_name": "test",
        "session": { // here
        "platform": "iOS",
        "device": {
            "os_name": "iPhone OS",
            "manufacturer": "Apple",
            "type": "iPhone3",
            "version": "1",
            "os_version": "5.1.1"
        },
        "app_version": "1.0",
        "device_id": "",
        "app_key": "1234567890",
        "developer_key": "",
        "app_name": "test"
    }
}

这是MappingJacksonConverter生成的数据,但我不知道如何禁用包含整个递归数据的“会话”字段。

HttpEntity<OlSession> sessionEntity = new HttpEntity<OlSession>(new OlSession());

ResponseEntity<String> response = restTemplate.postForEntity("http://localhost:3000/test/abcd", sessionEntity, String.class);

这是发布上述数据的代码。 我需要添加任何部分来禁用“会话”字段吗?

有两种简单的解决方案。

1)使用杰克逊注释忽略该属性。

但是通过这种方式,OlSession属性中的会话不会在任何地方被序列化。

@JsonIgnore
Object getSession() {
  return session
}

看看这个文件JacksonAnnotation

2)在发送前只需将其设置为null。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM