Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-558

Long in $date-values aren't parsed correctly by JSON.parse()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.7.2
    • Component/s: API
    • Environment:
      All

      When dumping a database or collection with dates -at least on Mac OS X and from .NET gererated Output- all date-data-object are encodes as timestamps in the form:

       { when : { "$date" : 1234567890000 } } // an unqouted Long value 

      when I try to parse such an String with JSON.parse(), I either get an java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String, if this timestamp is an unquoted Long or silently a null, if it was an quoted Long as in '"1234567890"'. Requesting such object leads e.g. to:

       { "when" : null } 

      I'm quite astonished that nobody found nor fixed this issue so far, since it is even an internally used format.

      I fixed this in JSONCallback.java by assuming first that the value is a parsable Long which can be turned into a Date-object. In case of an NumberFormatException ISODate is will be tried by applying defined SimpleDateFormat (Which is also no correct ISODate, since incomplete format. But this is another issue.)

      See attached patch.

            Assignee:
            bryan.reinero Bryan Reinero
            Reporter:
            tekto Adam Pordzik
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: