Skip to content

Support suppressed property when deserializing Throwable #3177

@klaasdellschaft

Description

@klaasdellschaft

Hi,

when using Jackson 2.12.x in my project to serialize / deserialize instances of Throwable, I noticed that the serialized JSON output contains the suppressed property. This property is also successfully filled in JSON if the original Throwable has suppressed exceptions. However, when deserializing the JSON back again to a cloned Throwable then this property is getting ignored, i.e. the cloned instance has an empty array of suppressed exceptions.

When debugging this issue, I think I narrowed it down to BeanDeserializerFactory.buildThrowableDeserializer(...) where the suppressed property is added to the ignorable properties.

// Java 7 also added "getSuppressed", skip if we have such data:
builder.addIgnorable("suppressed");

Based on the comment, I guess this ignoring of the suppressed property has historic reasons because it was only introduced in JDK 7, and only since jackson-databind 2.7 the Minimum JDK version is 1.7.

Given that the Minimum JDK version is even 1.8 since jackson-databind 2.12, what is your opinion on introducing deserialization support for the suppressed property? If you agree that this support should be introduced, I would give it a try to introduce it in BeanDeserializerFactory.buildThrowableDeserializer(...) and then send you a pull request. Most likely, I would implement it in a style similar to how the cause property of Throwable gets deserialized, i.e. I would add a manually constructed SettableBeanProperty that is using Throwable.addSuppressed(...) for adding the suppressed exceptions to the Throwable instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions