On Thu, Jun 11, 2020 at 10:45 AM Bertil Muth <[email protected]> wrote:
>
> Hi folks, I'm Bertil, I'm new to this group.

Hi Bertil. Welcome!

> I approached this problem from a different angle.
>
> I created a small facade library for Jackson that creates a specific builder 
> for the different cases, like those:
>
>     final ObjectMapper objectMapper =
>         json().property("@class").toSubclassesOf(Base.class).mapper();
>
>     // these both work
>     Foo foo1 = (Foo) objectMapper.readValue("{\"@class\": \"Foo\", \"value\": 
> 11}", Base.class);
>     Foo foo2 = objectMapper.readValue("{\"@class\": \"Foo\", \"value\": 12}", 
> Foo.class);
>
>     // so do these
>     Bar bar1 = (Bar) objectMapper.readValue("{\"@class\": \"Bar\", \"value\": 
> 21}", Base.class);
>     Bar bar2 = objectMapper.readValue("{\"@class\": \"Bar\", \"value\": 22}", 
> Bar.class);
>
>     // so do these (could have used standard ObjectMapper as well)
>     Foo foo3 = json().mapper().readValue("{\"value\": 13}", Foo.class);
>     Bar bar3 = json().mapper().readValue("{\"value\": 23}", Bar.class);
>
> The classes themselvers are anootation free:
> public class Base {
>   private int value;
>
>   public int getValue() {
>     return value;
>   }
>
>   public void setValue(int value) {
>     this.value = value;
>   }
>
>   @Override
>   public String toString() {
>     return "Base [value=" + value + "]";
>   }
> }
>
>
>
>
> I'd be really interested in your thoughts and comments.
>

First of all, thank you for sharing this. I think many users could
find this useful.

One question I have is this: do you think it would be easy to make
Moonwlker a regular Jackson module?
Module itself could be built using builder-style construction, and
then registered to ObjectMapper, just like any other module.
While this might be slightly less convenient than building using your
package (and there is also question
of how to handle modules your package depends), there would be some
benefits due to vast number of
other modules Jackson has. For example, this approach to polymorphic
handling could be used with other
Jackson-support dataformats: XML, YAML, CSV, CBOR, Smile etc.
Similarly support for datatype modules (Guava, Joda) could be added.

Or more generally -- since some or all of above is also possible by
just extending Moonwlker builder API --
it'd probably be good to allow full extensibility that Jackson modules
offer, and document that on README.

Anyway, thank you again for sharing this with everyone,

-+ Tatu +-

-- 
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/CAL4a10jUqMCUE_wtX784%2BdYQVj4Ca-PvNdAbP1-qE2pWQmVuKQ%40mail.gmail.com.

Reply via email to