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

Document.toJson incorrectly serializes Date

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 3.0.4, 3.2.2, 3.4.2
    • Component/s: Documentation, JSON
    • Labels:
      None
    • Environment:
      linux 4.9.9, openjdk 8u121, mongodb 3.4.1, mongodb-driver 3.4.2/3.2.2/3.0.4

      new Document("a", new Date(1483228800000L)).toJson() // same with JsonMode.STRICT
      

      produces

      { "a" : { "$date" : 1483228800000 } }

      but

      { "a" : { "$date" : "2017-01-01T00:00:00.000Z" } }

      or something similar expected.

      Date is serialized to format which differs with described in docs and used by mongoexport tools.

      If such behavior is expected and desired, than it should be at least mentioned in docs. It seems to be consistent through all 3.x drivers. Though mongoimport works fine with format produced by Document.toJson with current tools.

            Assignee:
            Unassigned Unassigned
            Reporter:
            grossws gross
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: