On Wed, Feb 27, 2019 at 3:48 AM Burak Emre Kabakcı
<[email protected]> wrote:
>
> 1. JsonNode doesn't actually have any magic under the hood. It uses 
> Map<String, JsonNode> for objects, List<JsonNode> for arrays and wrapper 
> objects for primitive types. Therefore, it's not memory efficient IMO so it 
> actually depends on your priorities:
>    1.1. If you care about the code complexity compared to memory bottleneck 
> or doesn't really have any schema, I would stick with JsonNode as it's 
> feature-rich and well-documented.
>    1.2. If you care about the performance and doesn't really have any option 
> to use class data binding, you may write your custom parser and deserialize 
> the JSON blob into a more compact representation such as Apache Avro rather 
> than JsonNode. If you have a

I disagree with this -- Apache Avro's in-memory model is not
significantly more efficient, but it is certainly much more cumbersome
to use, and requires strict schema to work with.
I would not recommend using that model for anything other than
possibly working with already Avro encoded data.
This is based on my work for Jackson Avro format backend.

But more specifically in this case, if there is no schema to use, one
would have to create Avro representation that would not offer any
benefits I can see. In fact it sounds like basic Maps, Lists, wrappers
approach is probably as good as it gets during processing: for storage
(for caching) it definitely can and should be encoded. This can be
done using Smile or CBOR format, which map naturally to Maps/List/etc
model.

> metadata store, you can basically parse the JSON blob, validate it and 
> convert them into Avro instances which will occupy less heap memory. We 
> prefer this approach as it also
> provides us a native way to validate the JSON blob.

I think that would perhaps make sense if you start with Avro Schema
(or avro encoded data), but otherwise there are alternative validation
mechanisms including Swagger and Java Bean validation (jsr-303).

> 2. AFAIK, JsonNodeFactory is thread-safe and stateless but it would be better 
> if someone who has experience with it could answer this question.

I would use `JsonNodeFactory` configured in `ObjectMapper for creating
root-level Object or Array, and then use methods Object/Array has for
constructing further values. They in turn use a node factory they were
created with.
In practice there isn't much difference from just using
JsonNodeFactory.instance (since custom node factories do not seem to
be common), but why bother carrying one around?

-+ Tatu +-

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to