FasterXML / FasterXML/jackson-module-kotlin

Way to ignore properties from delegate

Offen
#459 6 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
enhancement
Vorherrschende Sprache
Kotlin
Sterne
1.2k
Forks
187
Ø Merge
9 Std. 48 Min.
Gemergte PRs (30 T.)
16

Beschreibung

Hi, consider following code:

```kotlin
data class Base(
@JsonProperty("prop1") val prop1: String,
@JsonProperty("prop2") val prop2: String
)

data class Specific(
@JsonProperty("baseProps") val baseProps: Base,
@JsonProperty("prop3") val prop3: String
) : Base by baseProps
```

When using `objectMapper.writeValueAsString(specific)`, result JSON looks like this:

```json
{
"@type": "Specific",
"baseProps": {
"@type": "Base",
"prop1": "value1",
"prop2": "value2"
},
"prop1": "value1",
"prop2": "value2",
"prop3": "value3"
}
```

Is there a way to ignore all delegated properties from delegate `Base` without specifying every one of them using `@JsonIgnoreProperties`? Something like `@JsonIgnoreDelegates("baseProps")` would be great. The result should look like this:

```json
{
"@type": "Specific",
"baseProps": {
"@type": "Base",
"prop1": "value1",
"prop2": "value2"
},
"prop3": "value3"
}
```

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.