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

JSON.parse method doesn't support $type in $binary where type is a hexadecimal string

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.0
    • Affects Version/s: 3.0.0
    • Component/s: JSON
    • Labels:
      None

      Hi,

      as discussed on https://groups.google.com/d/msg/mongodb-user/ihCV6zWzWlg/u7Q-AKxBEQEJ

      The old "Json" package doesn't support the Extended JSON :

      $type is not a String but an Integer

      You can reproduce the problem with :

      final Document document = new Document("test", new BsonBinary("test".getBytes()));
      final String json = document.toJson();
      System.out.println(json);
      JSON.parse(json);

      and you got :
      { "test" :

      { "$binary" : "dGVzdA==", "$type" : "0" }

      }

      java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
      at com.mongodb.util.JSONCallback.objectDone(JSONCallback.java:127)
      at com.mongodb.util.JSONParser.parseObject(JSON.java:274)
      at com.mongodb.util.JSONParser.parse(JSON.java:227)
      at com.mongodb.util.JSONParser.parseObject(JSON.java:263)
      at com.mongodb.util.JSONParser.parse(JSON.java:227)
      at com.mongodb.util.JSONParser.parse(JSON.java:155)
      at com.mongodb.util.JSON.parse(JSON.java:92)
      at com.mongodb.util.JSON.parse(JSON.java:73)

      ($type, as I understand, must be an Integer but Extended JSon ask for a String)

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            twillouer William Delanoue
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: