johnzon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alessandro Moscatelli <alessandro.moscate...@live.com>
Subject R: R: Arrays / Lists elements polymorphic support
Date Fri, 18 May 2018 09:58:02 GMT
Hi there,
any news about making the polymorphic support part of JSONB api ?

Thank you
Alessandro

Da: Jean-Louis MONTEIRO<mailto:jeanouii@gmail.com>
Inviato: martedì 24 aprile 2018 14:17
A: dev@johnzon.apache.org<mailto:dev@johnzon.apache.org>
Oggetto: Re: R: Arrays / Lists elements polymorphic support

Wow, thanks for the quick turn around Romain.

Le mar. 24 avr. 2018 à 12:41, Romain Manni-Bucau <rmannibucau@gmail.com> a
écrit :

> Give it a try, you dont have that api portably yet I fear bit happy to be
> wrong.
>
> Le 24 avr. 2018 12:35, "Alessandro Moscatelli" <
> alessandro.moscatelli@live.com> a écrit :
>
> > And btw I can’t see the need for scanning in the first place :
> >
> > Step 1) While deserializing Collection<T>, when T is known at compile
> time
> > (damn type erasure), we can check if Class<T> has @JsonbTypeDeserializer
> > annotation. I believe this is what we are already doing (I hope so!). So
> > the specified Deserializer should be called,
> Polymorphic.DeSerializer.class
> > in this case.
> >
> > Step 2) Polymorphic.DeSerializer should check if Class<T> has
> > @Polymorphic.JsonChildren annotation, and also if specified children
> > classes have @Polymorphic.JsonId annotation. With all these information
> > deserialization can be done without scanning, I believe.
> >
> >
> > ________________________________
> > Da: Alessandro Moscatelli <alessandro.moscatelli@live.com>
> > Inviato: Tuesday, April 24, 2018 12:17:12 PM
> > A: dev@johnzon.apache.org
> > Oggetto: R: Arrays / Lists elements polymorphic support
> >
> > Conflict will still be possible if you choose the same id, or if you
> don’t
> > specify the id and the colliding simplenames of different classes will be
> > used.
> >
> > ‘Scanning’ could be done at Deploy time, on each entity with @Polimorphic
> > annotation only.
> >
> > The real gain would be the possibility to use Polymorphism without
> > modifying every entity referencing the polymorphic one, even more when
> you
> > could not even if you want (for example Collection).
> >
> > Another nice option would be to register children programmatically …
> >
> >
> > Da: Romain Manni-Bucau<mailto:rmannibucau@gmail.com>
> > Inviato: martedì 24 aprile 2018 12:06
> > A: dev@johnzon.apache.org<mailto:dev@johnzon.apache.org>
> > Oggetto: Re: Arrays / Lists elements polymorphic support
> >
> > 2018-04-24 11:46 GMT+02:00 Alessandro Moscatelli <
> > alessandro.moscatelli@live.com>:
> >
> > > Shouldn’t the @Polymorphic.JsonId (defaulting to simple name if absent)
> > be
> > > the meta to use to know what you will deserialize ?
> > >
> >
> > Yes, that's what it is actually but how do you find it?
> > Scanning? means you are slow for no real gain + you can conflict between
> > libraries and models
> >
> >
> > >
> > > By the way, how the Polymorphic.JsonId will be serialized ? This is not
> > > specified in the index.md.
> > >
> >
> > {_type: <id>,_value: <value>}
> >
> >
> > >
> > >
> > >
> > >
> > >
> > > ________________________________
> > > Da: Romain Manni-Bucau <rmannibucau@gmail.com>
> > > Inviato: Tuesday, April 24, 2018 11:42:13 AM
> > > A: dev@johnzon.apache.org
> > > Oggetto: Re: Arrays / Lists elements polymorphic support
> > >
> > > Not it wouldn't work since when you deserialize you don't have any meta
> > on
> > > what you will deserialize.
> > >
> > > There are alternative to this impl but this is the one requiring the
> > least
> > > configuration I think.
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <https://rmannibucau.metawerx.net/> | Old Blog
> > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Book
> > > <https://www.packtpub.com/application-development/java-
> > > ee-8-high-performance>
> > >
> > > 2018-04-24 11:39 GMT+02:00 Alessandro Moscatelli <
> > > alessandro.moscatelli@live.com>:
> > >
> > > > I think I would be great if this could be part of the Jsonb spec.
> > > > I noticed the lack of real support for polymorphism.
> > > >
> > > > Regarding your impl :
> > > >
> > > > What if you need a Collection of polymorphic entities ?
> > > > Wouldn’t it be better to declare the
> > > >
> > > >     @JsonbTypeSerializer(Polymorphic.Serializer.class)
> > > >     @JsonbTypeDeserializer(Polymorphic.DeSerializer.class)
> > > >
> > > > Directly on the root entity instead of declare them on the field ?
> > > > Would it work ?
> > > >
> > > > AM
> > > >
> > > > Da: Romain Manni-Bucau<mailto:rmannibucau@gmail.com>
> > > > Inviato: lunedì 23 aprile 2018 19:03
> > > > A: dev@johnzon.apache.org<mailto:dev@johnzon.apache.org>
> > > > Oggetto: Re: Arrays / Lists elements polymorphic support
> > > >
> > > > Ok
> > > >
> > > > Will try to adapt the impl we had and push it later today or tmr and
> > ping
> > > > here for feedbacks
> > > >
> > > > Le 23 avr. 2018 18:46, "Jean-Louis MONTEIRO" <jeanouii@gmail.com>
a
> > > écrit
> > > > :
> > > >
> > > > > That works for me.
> > > > > I agree that having that extension into a specific module is the
> way
> > to
> > > > go
> > > > >
> > > > > Le lun. 23 avr. 2018 à 18:44, Romain Manni-Bucau <
> > > rmannibucau@gmail.com>
> > > > a
> > > > > écrit :
> > > > >
> > > > > > Maybe raise a spec issue since we tend to be jsonb driven now.
> > Would
> > > be
> > > > > > great to not have a custom api for the id mapping.
> > > > > >
> > > > > > In the mean time we can push a jsonb-extra with that impl
> > > > > >
> > > > > > Le 23 avr. 2018 18:39, "Jean-Louis MONTEIRO" <jeanouii@gmail.com
> >
> > a
> > > > > écrit
> > > > > > :
> > > > > >
> > > > > > > Hey Roberto,
> > > > > > >
> > > > > > > I think that would be a great feature.
> > > > > > > Already had this case in the past and looks like Jackson
and
> Gson
> > > > > already
> > > > > > > have it.
> > > > > > >
> > > > > > > Gson subtypes on adapters.
> > > > > > > https://github.com/google/gson/blob/master/extras/src/
> > > > > > > main/java/com/google/gson/typeadapters/
> > > > RuntimeTypeAdapterFactory.java
> > > > > > >
> > > > > > >
> > > > > > > Jackson annotations with different strategies
> > > > > > > https://github.com/FasterXML/jackson-docs/wiki/
> > > > > > > JacksonPolymorphicDeserialization
> > > > > > >
> > > > > > > We should consider adding this feature I believe.
> > > > > > >
> > > > > > >
> > > > > > > Le mer. 18 avr. 2018 à 19:42, Roberto Cortez
> > > > > <radcortez@yahoo.com.invalid
> > > > > > >
> > > > > > > a écrit :
> > > > > > >
> > > > > > > >  Hi Romain,
> > > > > > > > Thanks for the quick response.
> > > > > > > > I'll have a look,
> > > > > > > > Cheers,Roberto
> > > > > > > >     On Wednesday, April 18, 2018, 6:35:32 PM GMT+1,
Romain
> > > > > Manni-Bucau
> > > > > > <
> > > > > > > > rmannibucau@gmail.com> wrote:
> > > > > > > >
> > > > > > > >  Hi Roberto
> > > > > > > >
> > > > > > > > Yes, an adapter is the way to go using our mapper
or jsonb.
> > > > > > > >
> > > > > > > > There should be an "animal" test showing how to do
that. Just
> > > dont
> > > > > > forget
> > > > > > > > to use class aliases or a whitelist logic to not open
a
> > backdoor.
> > > > > > > >
> > > > > > > > Since the model doesnt match the java model im not
a fan of
> > that
> > > > > > feature
> > > > > > > > being built out of the box. In xml it is more natural
but in
> > json
> > > > you
> > > > > > can
> > > > > > > > do it without breaking the model. For me it means
the model
> is
> > > > broken
> > > > > > and
> > > > > > > > must not be used as an input.
> > > > > > > >
> > > > > > > > Le 18 avr. 2018 19:31, "Roberto Cortez"
> > > > <radcortez@yahoo.com.invalid
> > > > > >
> > > > > > a
> > > > > > > > écrit :
> > > > > > > >
> > > > > > > > > Hi guys,
> > > > > > > > > I'm trying to serialize a list of elements of
multiple
> types
> > > and
> > > > > then
> > > > > > > > > deserialize it again. It does require to somehow
include
> the
> > > type
> > > > > in
> > > > > > > the
> > > > > > > > > serialization result to know to which type we
should map to
> > > > > > > deserialize.
> > > > > > > > I
> > > > > > > > > think this could possible be done with an Adapter
and
> playing
> > > > with
> > > > > > the
> > > > > > > > > JsonArray.
> > > > > > > > > I was just wondering if there any kind of out
of the box
> > > support
> > > > > for
> > > > > > > > this.
> > > > > > > > > It doesn't seem so, at least I was not able to
find.
> > > > > > > > > Jackson for instance, includes a set of annotations
that
> > allow
> > > > you
> > > > > to
> > > > > > > do
> > > > > > > > > exactly this, without any extra / custom code.
> > > > > > > > > Any thoughts?
> > > > > > > > > Thank you.
> > > > > > > > > Cheers,Roberto
> > > > > > >
> > > > > >
> > > > >
> > > >
> > > >
> > >
> >
> >
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message