简体   繁体   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"
    }
}

This is the data generated by MappingJacksonConverter but I don't know how to disable the "session" field containing the whole recursive data. 这是MappingJacksonConverter生成的数据,但我不知道如何禁用包含整个递归数据的“会话”字段。

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

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

This is the code to post the above data. 这是发布上述数据的代码。 Is there any part that I need to add to disable the "session" field? 我需要添加任何部分来禁用“会话”字段吗?

There are two simple solution. 有两种简单的解决方案。

1) Use jackson annotation to ignore that property. 1)使用杰克逊注释忽略该属性。

But in this way, session in OlSession property will not be serialized everywhere. 但是通过这种方式,OlSession属性中的会话不会在任何地方被序列化。

@JsonIgnore
Object getSession() {
  return session
}

Take a look this doc JacksonAnnotation 看看这个文件JacksonAnnotation

2) Just set null before you send. 2)在发送前只需将其设置为null。

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

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