question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@JsonUnwrapped not supported for Map-valued properties

See original GitHub issue

According to the documentation,

Annotation used to indicate that a property should be serialized “unwrapped”; that is, if it would be serialized as JSON Object, its properties are instead included as properties of its containing Object.

Unfortunately, this seems to work only with bean types, and does not work with Map<String, Object>. Given that bean types are generally completely interchangeable with Maps, it would be very nice if this worked correctly.

Issue Analytics

  • State:open
  • Created 11 years ago
  • Reactions:23
  • Comments:31 (15 by maintainers)

github_iconTop GitHub Comments

15reactions
marceloverdijkcommented, Apr 15, 2018

Unfortunately the @JsonAnyGetter does not work (easily) with Kotlin:

class Links(
        @JsonAnyGetter
        val links: Map<String, Link>
) : Serializable

as the annotation needs to put on a method.

!! UPDATE !!

It does work (easily):

class Links(
        @get:JsonAnyGetter
        val links: Map<String, Link>
) : Serializable

3reactions
Drucklescommented, Jun 16, 2021

About the only question I have is whether there are some specific differences between just using @JsonAnyGetter/@JsonAnySetter combo, and potential @JsonUnwrapped. … Or put another way: if @JsonUnwrapped was essentially implemented as sort of alias for “any-getter”, would that work?

I have the same problem as @odrotbohm: @JsonUnwrapped sits on top of a generic. To get it to work, I’ve needed to create subclass that overrides the getter so I can add @JsonAnyGetter. The any-getter doesn’t work because it’s of type T, not a Map and it throws an error during runtime otherwise.

This creates other problems because I’ve subclassed it. Being able to use @JsonUnwrapped would be much easier, cleaner and safer.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jackson JsonUnwrapped properties collision - Stack Overflow
When Outer objects are serialized - if inner is not null - Inner properties should be unwrapped, hence the @JsonUnwrapped usage.
Read more >
Security update for jackson-databind, jackson ... - SUSE
An update that fixes three vulnerabilities is now available. Description: This update for jackson-databind, jackson-dataformats-binary, ...
Read more >
FasterXML - Bountysource
@JsonUnwrapped not supported for Map-valued properties $ 0. Created 9 years ago in FasterXML/jackson-databind with 31 comments. According to the documentation,.
Read more >
Jacksonでtop levelのpropertyを省略してMap<K, V>をserialize ...
で,どうすると良いかというと @JsonUnwrappedを使うという方法がまず考え ... ています: @JsonUnwrapped not supported for Map-valued properties ...
Read more >
SUSE alert SUSE-SU-2022:1678-1 (jackson-databind ...
(bsc#1182481) Non security fixes: jackson-annotations - update from ... definitions for property + Deserialization Not Working Right with ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found