Quick way to get the keys of a JSON object passed to my POJO?

11 views
Skip to first unread message

Laird Nelson

unread,
May 2, 2023, 5:57:54 PM5/2/23
to jackson-user
Given a JSON object with, say, three keys mapped to three values, is there a way in Jackson 2.15 or later to annotate some setter method or constructor of my POJO to receive the set of such keys, known and unknown?

e.g. something like:

@JsonCreator //...
public MyPojoConstructor(@JsonKeys /* maybe? */ Set<String> keys, ...) {
  //...
}

I'm aware I can do all sorts of fancy custom things involving deserializers, @JsonAnySetter, etc. and composite the thing myself but this seemed like a use case that maybe others have had, and that therefore might have a "one shot" solution I'm simply overlooking.

Best,
Laird

Tatu Saloranta

unread,
May 2, 2023, 8:41:12 PM5/2/23
to jackso...@googlegroups.com
I can't think of any simple way to do this, no.
Appreciate you asking; there are many lesser known things that get
omitted. But this isn't one, unfortunately.

-+ Tatu +-

>
> Best,
> Laird
>
> --
> You received this message because you are subscribed to the Google Groups "jackson-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jackson-user...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/640aab98-10e0-4d28-bfe1-cc3afcceb7afn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages