forrestzhu / odata4j

Automatically exported from code.google.com/p/odata4j
0 stars 0 forks source link

JSON Parser Fails \/Date(123456789)\/ #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Pull version 0.4
2. Query an OData service with Date data.   ( 
http://services.odata.org/OData/OData.svc/Products?$format=json is a fine 
example. )
3. Iterate through the results.

During the Iterable.hasNext() call, an "IllegalArgumentException: invalid date 
format" is thrown.  I've attached sample code and the output from that code for 
reference.

I'm currently running Ubuntu 11.04 on 32-bit x86, but I don't think the 
environment is the issue.

The issue seems to be that JsonTypeConverter is expecting a '\/' at the 
beginning of the string, but JsonStreamReaderFactory.move() has stripped the 
'\' escape character before then.

I can suggest two solutions to this problem.

1. Modify JsonTypeConverter (currently at line 57) to accept '/Date(' and ')/' 
instead of '\/Date(' and ')\/'.  Quick and easy, but could lead to some rare 
false positives.

2. Modify JsonStreamReaderFactory.move() to append a solidus (U+2044) instead 
of a slash (U+002F). (now at line 371)  This will actually follow the JSON 
spec, and will help prevent false positives.  Right now, '/Date' and '\/Date' 
are parsed identically, which is not (should not) be true.  This also requires 
a modification to JsonTypeConverter.

I'm not too familiar with patch files (or contributing to open source projects 
in general), but I'd be happy to implement the changes if it'd be helpful, and 
if y'all can guide me through the process.

--Tim

Original issue reported on code.google.com by tcgar...@gmail.com on 1 Aug 2011 at 9:35

Attachments:

GoogleCodeExporter commented 8 years ago
When modifying JsonTypeConverter, at the initialization of String ticks the 
constant '3' must be changed to a '2' as well.

Original comment by tcgar...@gmail.com on 2 Aug 2011 at 4:03

GoogleCodeExporter commented 8 years ago
Tim,

thank you for pointing out this problem.

The following is copied from http://www.ietf.org/rfc/rfc4627.txt

string = quotation-mark *char quotation-mark

         char = unescaped /
                escape (
                    %x22 /          ; "    quotation mark  U+0022
                    %x5C /          ; \    reverse solidus U+005C
                    %x2F /          ; /    solidus         U+002F
                    %x62 /          ; b    backspace       U+0008
                    %x66 /          ; f    form feed       U+000C
                    %x6E /          ; n    line feed       U+000A
                    %x72 /          ; r    carriage return U+000D
                    %x74 /          ; t    tab             U+0009
                    %x75 4HEXDIG )  ; uXXXX                U+XXXX

         escape = %x5C              ; \

         quotation-mark = %x22      ; "

         unescaped = %x20-21 / %x23-5B / %x5D-10FFFF

This means "\/" is equivalent to "/". Since we know the property type when we 
convert the string to a LocalDateTime with the JsonTypeConverter, there should 
be no ambiguity. So I've changed only the JsonTypeConverter.

Rolf

Original comment by Mail.Rol...@googlemail.com on 11 Aug 2011 at 7:49

GoogleCodeExporter commented 8 years ago
Interesting, and thanks!

Original comment by tcgar...@gmail.com on 11 Aug 2011 at 2:13

GoogleCodeExporter commented 8 years ago

Original comment by john.spurlock on 1 Oct 2011 at 11:38

GoogleCodeExporter commented 8 years ago

Original comment by john.spurlock on 6 Nov 2011 at 3:10