Discussion:
JAX-RS: deserialization of org.json.JSONObject
Kean Erickson
2018-10-16 18:50:18 UTC
Permalink
Although the javax.json.JsonObject API at is now meant to be used instead,
it's interesting that org.json.JSONObject is properly deserialized in
JAX-RS. The only catch is that every json object nested inside is itself
nested as a value with a key called "map", such that if I had a structure
like this:

"a" : { "b" : "c" }

...the resulting output would be:

"a" : { "map" : {"b": "c"} }

The org.simple.JSONObject library would be completely usable for this
purpose if not for this one strange addition. I'm wondering where this
behavior originates, or the simplest way to change it?

I'm aware that the json processing API is meant to be used instead, but I
find it to be fairly inflexible compared to JSONObject for a few reasons,
so I'd prefer to use the latter if possible.

Thanks,
-Kean
Romain Manni-Bucau
2018-10-16 20:05:25 UTC
Permalink
Hi Kean

You can write a message body reader/writer to handle org.json.
Post by Kean Erickson
Although the javax.json.JsonObject API at is now meant to be used instead,
it's interesting that org.json.JSONObject is properly deserialized in
JAX-RS. The only catch is that every json object nested inside is itself
nested as a value with a key called "map", such that if I had a structure
"a" : { "b" : "c" }
"a" : { "map" : {"b": "c"} }
The org.simple.JSONObject library would be completely usable for this
purpose if not for this one strange addition. I'm wondering where this
behavior originates, or the simplest way to change it?
I'm aware that the json processing API is meant to be used instead, but I
find it to be fairly inflexible compared to JSONObject for a few reasons,
so I'd prefer to use the latter if possible.
Thanks,
-Kean
Loading...