Skip to content

Way to ignore properties from delegate #459

Open
@vladokvocka

Description

@vladokvocka

Hi, consider following code:

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:

{
    "@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:

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions