[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jsonb-dev] Custom deserialize array property
|
- From: Michael Lipp <mnl@xxxxxx>
- Date: Wed, 23 Oct 2024 13:38:05 +0200
- Autocrypt: addr=mnl@xxxxxx; keydata= xsFNBFbn8agBEADOKof+zVMwg1nwdw8eG7kYY3iy/zCD2S3l+hRy9yF5svnpBRa7WiTKNnRZ CtOBtmkTr54fkbnYnQK2y5hMyrWkpCij7MT4yAM/HCDJqS+Yfi7VT4Alt24rm3gZoSfmgqWl dt94BdunpiNfsVQdjXu87eaSiVkqyqb+6H0lquW6uZFR5/PuHMw/UbgkKgKW97k6OAyr+PTf 1HtLfmtykXyRMTnuny1fxpvA7UnU9u54UPfUn29F1ArF8NzfKVNn6bcnmuyWm6ORPoFLXlUB 3aA1RDY+wo5zJsce6M/8FT5/hi9U6b1K/uRGCXhgzz5Vxb3mtzpVqNSBTnlhIjJhS0dYnNdH QN4Ng96Na3ZzqW4GnBmXkGDT3lo7kXsIV+2cPMDcUfmaiOtRv/hgPj4cRiExvTpsEV4FBelX C96s5kb122h7MWwStalVY+CG2x/OLvho84/hPZf60YW/1quSpTMAseMqesc/V6AuY0ZPdR7r ei66e2uL+KbipkhDTN+p9h0XD2DryhAE4rmU4cSq3+CgYl0WEgitDXPoD18g04jqgIZ4oy81 xeBG93Xc2iODiy0khBv+SB4FxLrJXo1zhmFngRAhIG2nt3tYppIOTmMGV/dJr3YMR4OUegu7 eFy/6Q1naOtzXWMDaRwUtou2c6wzWYZvFTCfnxxNLQqOw1Fc6wARAQABzSVNaWNoYWVsIE4u IExpcHAgKFByaXZhdCkgPG1ubEBtbmwuZGU+wsF3BBMBCAAhBQJW5/GoAhsDBQsJCAcCBhUI CQoLAgQWAgMBAh4BAheAAAoJEBriMFiHjvWZbycQALKiZir3N8dTZkK0csdxXBR2zfXJQT3Q A4uvv/nxNpAWanHndWq721DCUuXTZU7UCap+WpmcvKQa9kM93XXx8782Z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h6vcnm8eQGo06M GHVK1NwOVQr4KNcRFLk4KFg7LigMI21dRs2WMxEBIugKF8PReP/hUg7av+XldYemgPAdWh9E 72qw9vOXTa8HO9VQIcKnXLhcd/QTI3aXeWDb+FTZXaFkLnY5aMx8zZYQYOaFJHWztI5jjNof jJMENyM0vFlNj/0JwTQjlncfZ2p6uM8ZR6RWLCj5/eqxw0joqLUSMwARAQABwsFfBBgBCAAJ BQJW5/GoAhsMAAoJEBriMFiHjvWZY/sP+wT9Y8QdjIxnl+6mRvZ+C2LEvRw/ABxrrxye0BLW KQSuwWTgHMwDAIRTXOWu2VC54UmyH+ds5tcv27215ueDYrxsNfMzwXYqA07K0aqvMDB/fn8+ 1NWm9EVNpfKKyJzvprAgqvYHS5Bkp+PiW0LAhctxRv1EpRMA2iHfTjttBoYcfAlsfrTAjCbN jCACUdOBwypog1gnUA18fFyXrGF3CRHPcqsgJOn1KPSbHeUgsqhc7XKcEUxIy37Co4qm06wq YKYr9XNCe0kjrftc+VEi/BK+uYlFR0Eq/trCsuSPJMzTM8O6wmkgngfMlNrRqgorwXwsgKFe PvMuGTO7cUB4BhQnm7rYJJCFoavijCQombRMZ+oA3N6eRcbQXd1++guEvPsivNNe1ZUuWpv5 YtkliMNHumrkHR3hE4mLZpgBslL8NsAI8kcmGmiFuV3Zv7alo9fkupBOulVSYZkSKqbV0rRY 6u5EIx2t05OsYSpBgE3T+hs2UVnGGjIpJSCiZDvOI1haMVRjkTutKAjbCAhgHIVeCTIIfsqi 3PYf6HYa+21YVMM+CvGOXXsOLYOOXYgkXsL1Gn5zQtwJP8rYezKtsuqMwfL7Vjc/scnsyHuG qeixyy3cll31vSFZ+mWh4Ze06FwqHg9YjWQidWrWCMz1XYXIWcIu8xagb/jZbLZilW65
- Delivered-to: jsonb-dev@xxxxxxxxxxx
- List-archive: <https://www.eclipse.org/mailman/private/jsonb-dev/>
- List-help: <mailto:jsonb-dev-request@eclipse.org?subject=help>
- List-subscribe: <https://www.eclipse.org/mailman/listinfo/jsonb-dev>, <mailto:jsonb-dev-request@eclipse.org?subject=subscribe>
- List-unsubscribe: <https://www.eclipse.org/mailman/options/jsonb-dev>, <mailto:jsonb-dev-request@eclipse.org?subject=unsubscribe>
- User-agent: Mozilla Thunderbird
Am 23.10.24 um 13:04 schrieb Romain
Manni-Bucau:
Hi Michael,
We got this issue as well in Johnzon and worked around the
JSON-B layer cause this is not practicable (deserializers are
not reusable and you must implement one per location - array,
property, ...).
I would be in favor of fixing JSON-B deserialization model
- with a JsonbConfig toggle for backward compatibility and
short term you implement a dedicated deserializer for the full
array?
I don't see how this could help. In my implementation, I still
couldn't use the DeserializationContext for deserializing the
elements of the array. So I'd have to re-implement my own
deserializers for all types (possibly) used as elements.
Speaking of Johnzon, the crude workaround is to simply ignore the
Javadoc. I've tried it and you can invoke the deserialize method
when the parser is positioned on the START_ARRAY (or the last
token of something deserialized before). Eventually, after the
last element, the deserialize will see the END_ARRAY (without
knowing about the START_ARRAY) and return an empty array that I
can use to terminate my loop. But this is nothing but an
unreliable hack, of course.
Hello,
if this is the wrong place for this topic, I apologize in
advance.
However, I couldn't find or think of anything better place.
I'm trying to port a deserializer from Jackson to Json-B. The
Json to
deserialize looks like this (simplified):
{
"prop1": "something",
"prop2": [ "something else", 42, { "attribute": "value" }
]
}
In addition, there is a Java type "class Something { public
String
attribute; }" that should be used for entry 2 in the array in
the result
of the deserialization (actually, the class is more complex).
When deserializing this, I know (from the "rtType" passed to
the
"deserialize" method of my deserializer) the Java types of the
elements
in the array in "prop2". Therefore, I don't want to forward
the
deserialization of the array to the DeserializationContext
because it
does not know about the types used in the array and would use
a Map for
the last element. I want to do it myself.
This is no problem with Jackson, because its equivalent to
DeserializationContext expects the parser to be positioned on
the start
token of the item to deserialize. I therefore consume the
START_ARRAY,
get the next token, check if it is END_ARRAY, and if it is
not, I make
Jackson deserialize the next (actually current) item with the
expected
Java type.
The Json-B apidoc for DeserializationContext#deserialize
states that
"JsonParser cursor have to be at KEY_NAME before START_OBJECT
/
START_ARRAY, or at START_OBJECT / START_ARRAY to call this
method." But
I cannot leave the cursor at "prop2", because then the
DeserializationContext deserializes using default types. Of
course, I
could post-process the result created with default mappings
and adapt it
to my expected type. But this requires additional coding and
additional
CPU cycles at run-time.
Is there any solution to this problem that I have missed or is
this
simply a use case that wasn't considered when specifying
Json-B?
- Michael
_______________________________________________
jsonb-dev mailing list
jsonb-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jsonb-dev