FasterXML / FasterXML/jackson-annotations

Add @JsonWrapped (to complement @JsonUnwrapped)

Offen
#42 16 Kommentare 89 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
1.1k
Forks
342
Ø Merge
8 Std. 53 Min.
Gemergte PRs (30 T.)
2

Beschreibung

Re-rasing this issue from the old Jira bug tracker: https://jira.codehaus.org/browse/JACKSON-781

It was suggested this should be raised in the [data bind](https://github.com/FasterXML/jackson-databind/issues) project, but as it is an annotation, this seemed a better fit.

This is the original issue description:

> @JsonUnwrapped allows people who want a more compressed JSON hierarchy than their POJO to affect the process, but there is no option for the reverse. I have a REST service producing unnecessary additional layers of abstraction that i would like to exclude from my Java POJOs rather than writing all sorts of unseemly wrapper classes.

I agree this would be a great feature to avoid unnecessary wrappers on the Java side when consuming JSON APIs.

I'd picture a new annotation that would take a form along the lines of:

``` java
@JsonWrapped("address")
@JsonProperty("house_number")
private String houseNumber;
```

or it could be an additional parameter of the `@JsonProperty` annotation:

``` java
@JsonProperty(value="house_number", wrapped="address")
private String houseNumber;
```

or, possibly, the value parameter of the `@JsonProperty` annotation could specify the object hierarchy:

``` java
@JsonProperty("address.house_number")
private String houseNumber;
```

This may introduce backwards compatibility issues, though, as it would mean this behaved differently than it currently does.

It would be good if it could also unwrap multiple levels, such as:

``` java
@JsonWrapped("contact_details.address")
@JsonProperty("house_number")
private String houseNumber;
```

Though, this would mean the value of the `@JsonWrapped` annotation was parsed differently than the value of the `@JsonProperty` annotation (as `"contact_details.address"` in the `@JsonProperty` annotation would refer to an object key named "contact_details.address").

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.