简体   繁体   中英

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.

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.

But in this way, session in OlSession property will not be serialized everywhere.

@JsonIgnore
Object getSession() {
  return session
}

Take a look this doc JacksonAnnotation

2) Just set null before you send.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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