ObjectReader's "hasNext()" and "next()" don't appear to do anything on the object scope, only on the object detail scope and deeper.
How are we intended to iterate through multiple objects in one file?
In order to do this I had to implement two hacks; one to insert line breaks between every object in ObjectWriter:
objectwriter.flush(); printwriter.write("\n");
And one to calculate the # of lines in a saved file via a BufferedReader, so that I could do
while (objectreader.row() < linecount)
to finally gain the ability to iterate through multiple objects.
I probably would have done the line-break hack anyway just to make it more readable (surprised this isn't either the default or an option), but this seems like a kind of silly/hackish solution to something that I assumed would be dead simple.
Am I just missing something here or is this just a strange omission in functionality?
--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/b73359bf-db1f-4c6d-b846-3ac4c26be192%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi John,
I’ve made a fix for this + implementing both options, I have also pushed a snapshot to sonatype, you can get it here.
Is this kind of API/behaviour that you were expecting? So for example to bind a a sequence of object (not enclosed in an array) you would do the following:
Genson genson = new GensonBuilder().usePermissiveParsing(true).create();
ObjectReader reader = genson.createReader(json);
for (Iterator<LogEntry> it = genson.deserializeValues(reader, GenericType.of(LogEntry.class));
it.hasNext(); ) {
// do something
LogEntry p = it.next();
}
You can also use directly the ObjectReader:
for (ObjectReader reader = genson.createReader(new StringReader("{\"a\":1}{\"a\":2}"));
reader.hasNext(); reader.next()) {
reader.beginObject();
// advances to the key value pair and consumes it.
reader.next();
System.out.println(reader.name()+"="+reader.valueAsInt());
reader.enbObject();
}
Eugen
new GensonBuilder().usePermissiveParsing(true).create();
Could you please provide some small example (json+code that reads it) that does not work with the snapshot version?--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/604da4a0-0458-47ef-906c-8f180a398d00%40googlegroups.com.
Ah strange, can't see any other attempt on the google group...
Great, I will make a release next week.
You are welcome :)
Eugen
--
You received this message because you are subscribed to the Google Groups "Genson user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genson+un...@googlegroups.com.
To post to this group, send email to gen...@googlegroups.com.
Visit this group at http://groups.google.com/group/genson.
To view this discussion on the web visit https://groups.google.com/d/msgid/genson/dec51f99-49a5-4e71-97e6-c8a6336f899b%40googlegroups.com.