json_generator_set_root() not memory efficient
If I understand it correctly, calling json_generator_set_root()
makes a copy of the passed-in JsonNode
, which means it'll use twice more memory.
Is that correct observation?
I'd like to create (possibly large) JsonObject
-s with JsonBuilder
and then pass this to JsonGenerator
to make it a string, which will be passed over network to the destination. As it may mean the (possibly large) JsonObject
-s, I'd prefer to avoid duplication of the data in the memory.
I think the current workaround would be to not use JsonBuilder
at all, rather create the root JsonNode
, set it immediately to the JsonGenerator
, free the node and read back the one inside the generator and then fill the node with the object (again, without using JsonBuilder
). Am I right?