org.bson.Document#parse(java.lang.String) fails when there is a null value for a $date field

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Declined
    • Priority: Major - P3
    • None
    • Affects Version/s: 4.8.2, 5.5.1
    • Component/s: BSON, Codecs, JSON
    • None
    • None
    • Java Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      The method org.bson.Document#parse(java.lang.String) fails for a valid JSON string when there is a null value for a $date field in the JSON string. Example below in How to Reproduce section.

      Driver version: 4.8.2, 5.5.1

      Server version: Not applicable

      How to Reproduce

      JSON String:
      {
      "name" : "abc",
      "dateField" : {
      "$date" : null
      }
      {color:#cccccc}}
      This fails with

      Exception in thread "main" org.bson.json.JsonParseException: JSON reader expected an integer or string but found 'null'.
          at org.bson.json.JsonReader.visitDateTimeExtendedJson(JsonReader.java:1052)
          at org.bson.json.JsonReader.visitExtendedJSON(JsonReader.java:626)
          at org.bson.json.JsonReader.readBsonType(JsonReader.java:166)
          at org.bson.codecs.DocumentCodec.decode(DocumentCodec.java:174)
          at org.bson.codecs.DocumentCodec.decode(DocumentCodec.java:44)
          at org.bson.Document.parse(Document.java:129)
          at org.bson.Document.parse(Document.java:114)

      The same JSON string when inserted via MongoDB Compass, is able to automatically detect that a null value is provided for the $date field and considers that as a JSON object and inserts it.

      MongoDB shell works too:

      db.test.insertOne({ dateField: {"$date" : null)}}

      Ideally, the Document.parse method should be able to dynamically handle this as Compass and Mongo shell does.

       

              Assignee:
              Valentin Kavalenka
              Reporter:
              Kiruphasankaran Nataraj
              None
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: