Byte array encoding/decoding missmatch

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Codecs
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The following test fails with AssertionError: expected:<class [B> but was:<class org.bson.types.Binary>

          @Test
          public void testByteArray() {
              MongoClient mongo = new MongoClient();
              MongoDatabase db = mongo.getDatabase("mydb");
              MongoCollection<Document> collection = db.getCollection("test");
              try {
                  collection.insertOne(new Document("image", "MongoDB".getBytes()));
                  assertEquals(byte[].class, collection.find().first().get("image").getClass());
              } finally {
                  collection.drop();
                  mongo.close();
              }
          }
      

      It appears, byte array is encoded properly with ByteArrayCodec, but is decoded to BsonBinary, by BinaryCodec.

      Probably BinaryCodec should be obsoleted, and removed from ValueCodecProvider.addCodecs, and BsonTypeClassMap.addDefault() should have map.put(BsonType.BINARY, byte[].class) instead of map.put(BsonType.BINARY, Binary.class)

            Assignee:
            Ross Lawley
            Reporter:
            Andriy Zhdanov
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: