[英]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.