Sorry, me again :)
In org.bson.json.JsonWriter
especially in org.bson.json.JsonWriter#doWriteBinaryData
default:
writeStartDocument();
writeString("$binary", printBase64Binary(binary.getData()));
writeString("$type", Integer.toHexString(binary.getType() & 0xFF));
writeEndDocument();
$type is not a String but an Integer (
http://docs.mongodb.org/manual/reference/bson-types/)
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)