java - Jackson - Working with arrays of objects, appending and removing -


I am working with the Jackson API in Java to handle JSON. I'm working here a bit more with it, but nothing deeply about it.

Currently, I'm looking for a good way to take an array of JSON objects (either through the stream or string) which was created from a list of POJOs and attached a POJO or add attachment In the case of doing, duplicate checking is not really necessary as a simple example, suppose I created this array from a list of Java objects with a single variable called "object":

  [{"field": "value"}, {" Hild ":" value2 "}]   

And I want to set the same object with a set" field "" value3 ". I can change the whole array into a list of Java objects, add new objects, then it can be backed up in JSON, but it seems that overkill would be better if I used the Jackson to just create a new object I can add it to the end of the JSON array. Deleting an existing object from the same array will apply.

I have found a way, but odd, it has 500 POJOs on each of the three areas With a list, the deserialize-ed-reserialze method is as slow as twice as a method, and it gets worse with only more items.

  ObjectMapper Map Maker = New ObjectMapper (); Jason Parser parser = Mapper.JetsenFacture (). Create Jonaspacer (input); JsonGenerator gen = mapper.getJsonFactory () CreateJson Generator (Output, JSON Encoding.Utf 8); Gen.writeStartArray (); Parser.nextToken (); While (parser.nextToken () == JsonToken.START_OBJECT) {//gen.writeTree (parser.readValueAsTree ()); //parser.skipChildren (); / Edit: It is very fast as the only method in the loop: gen.copyCurrentStructure (parser); } Gen.writeTree (mapper.valueToTree (/ * to add new object * /); gen.writeEndArray (); gen.close (); parser.close ();   

Even if I do not get each object in the form of a tree and instead iteratively forces the fields as steps for it, it is quite slow compared to a bit faster option but still Does it have to be expected or is there a better way to handle it as streaming data? No force Edit

Comparing JSON to JSON with JSON Method: Here we can find that JsonGenerator can directly copy the current structure from a JsonParser with the copyCurrentStructure (JsonParser) While it is fast to use in the loop and now the Brutfone method has been excluded from a considerable amount.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -