Polymorphic Serialization of Enums

59 views
Skip to first unread message

Eero Aaltonen

unread,
Nov 6, 2015, 8:41:50 AM11/6/15
to Genson user group
I have a use case where I have a mixed enums with generics. It looks like the problem might be solvable using a custom Converter, but I am unsure how exactly to achieve that.
I put the full on question on Stack Overflow

because of the formatting, search and rep features.

Cheers,
Eero

Eugen Cepoi

unread,
Nov 6, 2015, 6:45:41 PM11/6/15
to gen...@googlegroups.com
Hi Eero!

I just answered on SO with a solution to your problem.
The solution is generic enough to work with all kind of other situations, which should be great for you.

I would like to include it in Genson but don't have very much time right now and want to involve more the library users to become contributors.
If you are interested in contributing it would be great if you could take the time to think about my solution and open a PR so we make it part of Genson.
This would imply making sure it works well with the other features (useClassMetadataWithStaticType to false, runtime types etc), is configurable enough (disabled by default and enabled via a new option in the builder) and is disabled for primitive types (we don't need type info for them, this is already part of JSON format).
If you need help for this I can provide some.
Otherwise I will probably do it later on my self.

Thanks!
Eugen


--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/e60d508b-dfc6-4ecd-92b8-87bdd9cb04a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eero Aaltonen

unread,
Nov 11, 2015, 11:30:48 AM11/11/15
to Genson user group
Hi Eugen!

I implemented a solution where I registered a custom Converter only for enum types. It solves my immediate problem.
I agree with your design points. Ideally the decision between JSON object and raw value serialization could be made on whether the current context provides static type information. Is something like this currently available or would it also need be implemented?

BR,
Eero

Eugen Cepoi

unread,
Nov 16, 2015, 1:48:36 PM11/16/15
to gen...@googlegroups.com
It is accessible in some way (when providing the converters using a factory for example) but the thing is that when we use runtime ser/de the actual type is the concrete one and we loose track of the static type. So this would need to be handled in some way.
I will have a look later on how to handle this.

BTW, why did you use a custom converter for enums instead of the one I posted on SO? If it is because it didn't work for you I'd really like to know, as I am thinking of using something very similar if I have to implement this feature.

Thanks,
Eugen

Eero Aaltonen

unread,
Nov 17, 2015, 4:48:58 AM11/17/15
to Genson user group
On Monday, November 16, 2015 at 8:48:36 PM UTC+2, eugen wrote:

BTW, why did you use a custom converter for enums instead of the one I posted on SO? If it is because it didn't work for you I'd really like to know, as I am thinking of using something very similar if I have to implement this feature.

Mostly because I did not understand it. However comparing the two the difference is that what I wrote writes the metadata in "@class".
The actual serialized form that I ended up with is:

"value":{
    "@class":"RainState",
    "value":"LIGHT_RAIN"
}

Regards,
Eero

raphina tobias

unread,
May 26, 2024, 10:15:21 PMMay 26
to Genson user group

If you're interested in exploring the world of psychedelic mushrooms, you may be wondering if it's possible to buy shrooms online. The good news is that there are many online retailers that offer a wide range of mushroom products, from dried mushrooms to capsules, edibles, and more.

With a large selection of products to meet our clients' demands, Buy Psychedelics Online Shop is your go-to online drug store. We work hard to provide the best Legal Psychedelics For Sale Online and ship our goods internationally from everywhere. All of the items mentioned on our website are in stock. When you email us your request, anticipate that your order will be completed right away. Buy Psychedelics is a reputable & top rated online Psychedelic dispensary with over 10,000 heartfelt customer reviews from satisfied customers. We are experts in magic mushrooms and other psychedelic drugs. Whether you’re experimenting with psychedelic drugs, looking for a great trip or you’re ready to dive deeper in unlocking your mind, you have come to the right place.



https://t.me/bignugs/782
https://t.me/bignugs/780
https://t.me/bignugs/777
https://t.me/bignugs/761
https://t.me/bignugs/757
https://t.me/bignugs/744
https://t.me/bignugs/739
https://t.me/bignugs/736
https://t.me/bignugs/733
https://t.me/bignugs/729
https://t.me/bignugs/716
https://t.me/bignugs/699
https://t.me/bignugs/694
https://t.me/bignugs/693
https://t.me/bignugs/684
https://t.me/bignugs/661
https://t.me/bignugs/656
https://t.me/bignugs/655
https://t.me/bignugs/654
https://t.me/bignugs/653
https://t.me/bignugs/647
https://t.me/bignugs/643
https://t.me/bignugs/646
https://t.me/bignugs/626
https://t.me/bignugs/627?single
https://t.me/bignugs/616?single
https://t.me/bignugs/615?single
https://t.me/bignugs/611?single
https://t.me/bignugs/608?single
https://t.me/bignugs/618?single
https://t.me/bignugs/605?single
https://t.me/bignugs/599?single
https://t.me/bignugs/603?single
https://t.me/bignugs/606?single
https://t.me/bignugs/594?single
https://t.me/bignugs/592?single
https://t.me/bignugs/591?single
https://t.me/bignugs/589?single
https://t.me/bignugs/588?single
https://t.me/bignugs/587?single
https://t.me/bignugs/586?single
https://t.me/bignugs/583?single
https://t.me/bignugs/580?single
https://t.me/bignugs/579?single https://t.me/bignugs/585?single
https://t.me/bignugs/577?single
https://t.me/bignugs/574?single
https://t.me/bignugs/575?single
https://t.me/bignugs/571?single
https://t.me/bignugs/567?single
https://t.me/bignugs/563?single
https://t.me/bignugs/560?single
https://t.me/bignugs/551?single
https://t.me/bignugs/550?single
https://t.me/bignugs/548?single
https://t.me/bignugs/549?single
https://t.me/bignugs/533?single
https://t.me/bignugs/529?single
https://t.me/bignugs/524?single
https://t.me/bignugs/523?single
https://t.me/bignugs/525?single
https://t.me/bignugs/528?single
https://t.me/bignugs/518?single
https://t.me/bignugs/495?single
https://t.me/bignugs/492?single
https://t.me/bignugs/497?single
https://t.me/bignugs/467?single
Reply all
Reply to author
Forward
0 new messages