Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the need of defining a flat POJO that maps its (flat) attributes to a nested object in its JSON specification. Better explain with code

{
    "offset": 0,
    "pageSize": 10,
    "filter": {
        "key1":"value1",
        "key2": true,
        ....
    }
}

My POJO shall look like the following:

public class Pojo {
    private int offset;
    private int pageSize;

    private String key1;
    private boolean key2;
}

So far I have tried annotating those key properties with @JsonProperty with its value attribute

@JsonProperty("filter.key1")
private String key1;

But when I went into the MVC controller those properties, though set in JSON, were null in the decoded POJO.

How can I fix this? What did I do wrong?

I absolutely don't want to create nested subclasses

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
274 views
Welcome To Ask or Share your Answers For Others

1 Answer

Might be currently impossible.

This because Jackson currently supports @JacksonUnwrapped for the opposite case, but no @JacksonWrapped

Feature request: https://github.com/FasterXML/jackson-annotations/issues/42


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...