{ "id": "957c43f2-fa2e-42f9-bf75-6e3d5bb6960a", "name": "The Best Product", "brand": { "id": "9bcd817d-0141-42e6-8f04-e5aaab0980b6", "name": "ACME Products", "owner": { "id": "b21a80b1-0c09-4be3-9ebd-ea3653511c13", "name": "Ultimate Corp, Inc." } } }
public class Product { // ... @SuppressWarnings("unchecked") @JsonProperty("brand") private void unpackNested(Map<String,Object> brand) { this.brandName = (String)brand.get("name"); Map<String,String> owner = (Map<String,String>)brand.get("owner"); this.ownerName = owner.get("name"); } }
- 注意这个 unpackNested 方法,更多详情:https://www.baeldung.com/jackson-nested-values