简体   繁体   中英

Inner object deserialization with Jackson

I have a json

{
"params": [
    {
        "key": "path",
        "options": {
            "string": {
                "prefix": "test_pref"
            }
        },
        "default": {
            "url": ""
        }
    }
]}

I have the following POJO class, where i want to map inner objects like option.string.prefix in json to prefix in Params POJO class.

@Data
@Accessors(chain = true)
public class Data {
    private List<Params> params;
}

@Data
@Accessors(chain = true)
public class Params {

    private String key;

    @JsonProperty("options.string.prefix")
    private String prefix;

    @JsonProperty("default.url")
    private String url;
}

Is there any Jackson annotation that helps me do this without @JsonProperty?

The is @JsonGetter which is an alternative to @JsonProperty You can read a very nice article on the topic here: Jackson Annotation Examples

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