0

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?

grav
  • 1
  • 1
  • I don't think Jackson can do this out of the box. `@JsonProperty` as used will probably result in a JSON object as `{ "options.string.prefix": "test_pref", ... }`(not what you want). There is an annotation, `@JsonUnwrapped` that does the *opposite* of what you want. You will probably have to resort to custom `JsonDeserializer`/`JsonSerializer` implementations. – Nikos Paraskevopoulos Aug 29 '22 at 12:13

1 Answers1

0

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

Michael Gantman
  • 7,315
  • 2
  • 19
  • 36