I think for the moment I will try to create a custom serializer / deserializer for my properties map - Serializer: introspect the map and build JavaType then call the appropriate serialize - Deserializer: convert first into a TreeNode and then introspect the TreeNode (basically, if map and @type then try to create the associated deserializer)
On Mon, 18 Jul 2022 at 12:02, [email protected] <[email protected]> wrote: > Hello, > > I hope my question will not be another "why doesn't Jackson find > polymorphic type for my Map values (or List or Set)" and I hope I did my > best to check for any question/answer :). > > I have a bean with an any field: > @JsonAnyGetter > @JsonAnySetter > protected Map<String, Object> properties = new HashMap<>(); > > When initializing the map with: > properties.put("foo", new FooBean()); > properties.put("foos", List.of(new FooBean())); > properties.put("long", 123); > properties.put("longs", List.of(123)); > properties.put("longss", List.of(List.of(123))); > > I want to produce: > { > "foo": { > "@class": "org.FooBean", "foo": "bar" > }, > "foos": [ > { > "@class": "org.FooBean", "foo": "bar" > } > ], > "long": 123, > "longs": [123, 567], > "longss": [[123], 567] > } > > ie. a type for bean but not for primitive or collection/map. > > Is this use case achievable by using jackson? To quote that post > <https://groups.google.com/g/jackson-user/c/aHHmeZW37Es/m/yhPhZBbmBwAJ> *if > there'd be an option that says, if there is a type attribute at the > beginning, create this type, rather than a natural one. * > > Thanks for your help > > Nicolas > > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "jackson-user" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/jackson-user/abEAvuiMeac/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jackson-user/f62bae35-a14e-4f9f-b152-6bfcf2e83873n%40googlegroups.com > <https://groups.google.com/d/msgid/jackson-user/f62bae35-a14e-4f9f-b152-6bfcf2e83873n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jackson-user/CAEWXQ0oD_Xb%2B9pve35uzmsTWgvfMqT%2BDzaDNSb7kHROyPpQCgw%40mail.gmail.com.
