jsr367-experts@jsonb-spec.java.net

[jsr367-experts] Re: Fwd: Re: [jsonb-spec users] Java polymorphism support

From: Przemyslaw Bielicki <pbielicki_at_gmail.com>
Date: Mon, 21 Mar 2016 08:32:42 +0100

Hi,

I'm not a fan of the original idea (and it's an euphemism). Remember that
JSONB is used to serialize/deserialize DTOs, not domain objects. You should
have an additional adapter layer to convert DTOs into application's
business model/domain objects and back.
Polymorphism is broken (yeah, it's another topic and more philosophic) and
I would discourage its application in DTO layer. If you have to, you can
use an enum to mark what's the target class (check JPA for additional
inspirations). "//javaType": "x.y.z" is really bad idea IMO - what if you
use the same JSON to communicate with applications developed in .net,
python, php, c++ at the same time? (yes, it happens). Would you define a
type for each platform?

If you use DTOs in business layer, you're doing something wrong :)

@Romain, your idea looks interesting, can you show and example or
deserialization process where polymorphism is involved?

Cheers,
Przemyslaw

On Sun, Mar 20, 2016 at 10:52 PM, Romain Manni-Bucau <
rmannibucau_at_tomitribe.com> wrote:

> Hi guys
>
> Why not allowing adapters to wrap and unwrap instances but keep serializer
> mecanism. For serialization no issue but for deserialization we need to
> switch the deserialized type and then post process the instance - or do it
> automatically with an Unwrappable interface?
>
> Overall idea for this particular use case would be:
>
> X ----TypedWrapper(X)----> JSON
> JSON----TypedWrapper.class----> TypedWrapped ----unwrap----> X
>
> Parts in arrows are adapter/jsonb integration.
>
> An alternative is to provide to adapters the stream and jsonp instances to
> do it themself with probably a mapper reference to re(de)serialise an
> object directly.
>
> Wdyt?
> ---------- Message transféré ----------
> De : "Romain Manni-Bucau" <rmannibucau_at_tomitribe.com>
> Date : 19 mars 2016 21:49
> Objet : Re: [jsonb-spec users] Java polymorphism support
> À : <users_at_jsonb-spec.java.net>
> Cc :
>
> Hi Sebastian
>
> I am not fan of that - Mark knows ;) - and in particular now I'm sure we
> shouldnt do it: the 0-day vulnerability is still there and you open the
> door to the same issue or a complicated config adding this feature in
> something as generic as jsonb.
> Le 19 mars 2016 21:28, "Sebastian Daschner" <java_at_sebastian-daschner.de>
> a écrit :
>
>> Hi experts,
>>
>> I don't know whether this has been discussed in the mailing list before
>> but a needed functionality would be to specify the Java type of
>> properties in the serialized JSON.
>>
>> As JSON doesn't standardize comments or other "attributes" (like XML
>> does) a "magic property" could be added.
>>
>> Please see the proposal (explored by Mark Struberg, Reinhard Sandtner
>> and myself) on my blog:
>>
>> https://blog.sebastian-daschner.com/entries/json_mapping_polymorphism_support
>>
>> WDYT?
>>
>>
>> Cheers,
>> Sebastian
>>
>>