Let’s say I have a JSON array like:
[
"item1": {...},
"item2": {...},
"item3": {...}
]
What I’d like to do is to find the size in bytes of each item, so for example if item1
was {}
that’d be 2.
A way of doing this would be to:
- Deserialize it into a
List<Object>
. - Serialize each item into a
String
orbyte[]
. - Get the length of each serialized item.
But I’m looking for something more efficient, where I can skip the serialization step.
Deserializing each item into a JSON string would solve this, but I couldn’t find a way of making that work, since it isn’t officially supported.
Any ideas will be appreciated.
1