Struggles while supporting a "One Of" data type #1330
Unanswered
Jonathan-Zollinger
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
this server I'm consuming has one field which can be one of 5 types and I feel like I'm over complicating how to support this.
Data Examples
The data I'm consuming is the field in Zendesk's ticketing api for custom fields - it's pretty basic so I'm kinda frustrated I'm struggling with this. the json has two properties, an ID of type long and a nullable property called "value" whose value can either be a a number with no decimals, a number with two decimal points, boolean, String or lastly an array of strings.
{id: 123456, "spam and eggs" },{"id": 654321, false },{"id": 99, "value": ["alpha", "beta"]}'What I've tried
since micronaut uses jackson, I read up on jackson's implementation of polymorphic deserialization and came up with the below (along with each of the classes with similar annotations), but I couldn't work through errors stating that no default constructor could be found in my tests.
example implementing class
Like I said, I couldn't get this to work - in my tests I kept getting errors stating that jackson couldn't find constructors to use. similarly I tried implementing jackson's deduction based serialization but couldn't get anywhere that way either
My Overcomplicated take
what I've currently written that is working but makes me think I've gone about this wrong because of how complicated it is.
DTO
Serde implementation
Test:
Wrap Up
ultimately I can't help but think I'm overcomplicating this. technically my tests are passing, but I haven't even gotten to testing the encoding portion of the serde class, which I'm sure isn't working in its current state.
Can anyone point out how this is meant to be done with micronaut's serialization? I appreciate any help, thanks!
Beta Was this translation helpful? Give feedback.
All reactions