Lovelyxredxpanda / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

Streaming API augmentation on lexer #70

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It was a few years ago since last time I suggested this, so I thought I would 
try again:

I've implemented a streaming API on top of the json-simple lexer. It would be 
cool to see it in the official release. It's way speedy, I use it to parse GB 
sized JSON files.

JSONStreamReader:
https://github.com/karlwettin/json-simple-kalle/blob/master/src/main/java/org/js
on/simple/parser/JSONStreamReader.java

Buffered stream reader that allows for lookahead and moving forth and back in 
the stream:
https://github.com/karlwettin/json-simple-kalle/blob/master/src/main/java/org/js
on/simple/parser/BufferedJSONStreamReader.java

JSON beautifier on top of the streaming API:
https://github.com/karlwettin/json-simple-kalle/blob/master/src/main/java/org/js
on/simple/parser/JSONFormatter.java

Streaming based POJO de/serialization kit with some limitations (no 
matrices[][]):
https://github.com/karlwettin/json-simple-kalle/tree/master/src/main/java/org/js
on/simple/serialization

The code is currently Java 1.5 and all but the de/serialization kit would be 
easy to back port to 1.2

Original issue reported on code.google.com by karl.wet...@gmail.com on 17 Apr 2012 at 5:49

GoogleCodeExporter commented 9 years ago
Thank you Karl for your work. I will review it and try to incorporate it in the 
official release. Would you agree to release your codes under Apache 2.0 
license?

Original comment by fangyid...@gmail.com on 17 Apr 2012 at 8:54

GoogleCodeExporter commented 9 years ago
It's already blessed with ASL2.

Original comment by karl.wet...@gmail.com on 17 Apr 2012 at 9:00

GoogleCodeExporter commented 9 years ago
Sorry Karl, I have been making you waiting for quite a long time.

Original comment by fangyid...@gmail.com on 4 Jul 2012 at 5:51

GoogleCodeExporter commented 9 years ago
No worries. The code will need some cleaning up from debug stuff. Let me know 
and I'll do that for you. I don't care so much about the Bean serialization, 
mainly because it feels like a huge job to downport it to Java 1.2, but it 
would be really cool if the other stuff made it in.

I'm not sure about the reasons for Java 1.2 in json-simple, but since none of 
this code taint any of the core code perhaps you don't need to worry about all 
of this being JDK7.

Original comment by karl.wet...@gmail.com on 4 Jul 2012 at 2:39

GoogleCodeExporter commented 9 years ago
Also notice this in JSONFormatter.java when you implement BigDecimal:

        } else if (Double.class.equals(input.getObjectValue().getClass())) {
          output.write(input.getDoubleValue().toString());
        } else if (Long.class.equals(input.getObjectValue().getClass())) {
          output.write(input.getLongValue().toString());
        } else {
          throw new RuntimeException("Unsupported class: " + input.getObjectValue().getClass());
        }

Original comment by karl.wet...@gmail.com on 4 Jul 2012 at 2:44

GoogleCodeExporter commented 9 years ago
I was cleaning up the code a bit when I noticed something.

JSONStreamReader really just is a clone of JSONParser with the unmarshaling to 
JSONObject and JSONArray commented out and replaced by returning events. Thus 
any lexer change that affect JSONParser also needs to be updated in 
JSONStreamReader.

Perhaps it is a good idea to refactor so the unmarshaling currently in 
JSONParser is moved to a visitor or something like that, allowing for sharing 
the actual parser only.

Let me know how you feel about it and I'll try to come up with a patch.

Original comment by karl.wet...@gmail.com on 4 Jul 2012 at 4:09

GoogleCodeExporter commented 9 years ago
Attached patch containing cleaned up JSONStreamReader, BufferedJSONStreamReader 
and JSONFormatter down ported to Java 1.2, a bit of java docs, and test cases.

Original comment by karl.wet...@gmail.com on 5 Jul 2012 at 12:18

Attachments:

GoogleCodeExporter commented 9 years ago
Forgot to mention, the patch also contains JSONValue#escape(String, Appenable).

Original comment by karl.wet...@gmail.com on 5 Jul 2012 at 12:21