@Override public Symbol decode(final BsonReader reader, final DecoderContext decoderContext) { return new Symbol(reader.readSymbol()); }
return new Code(reader.readJavaScript()); case SYMBOL: return new Symbol(reader.readSymbol()); case JAVASCRIPT_WITH_SCOPE: return new CodeWScope(reader.readJavaScriptWithScope(), (BSONObject) readJavaScriptWithScopeDocument(reader));
/** * Tests if {@code Symbol} objects can be deserialized * @throws Exception if something goes wrong */ @Test public void symbol() throws Exception { org.bson.types.Symbol sym = new org.bson.types.Symbol("symbol"); TC.S obj = generateAndParse(sym, TC.S.class); assertEquals(sym.getSymbol(), obj.obj.getSymbol()); }
/** * Test if a complex BSON object containing various values can be * deserialized * @throws Exception if something goes wrong */ @Test public void parseComplex() throws Exception { BSONObject o = new BasicBSONObject(); o.put("Timestamp", new BSONTimestamp(0xAABB, 0xCCDD)); o.put("Symbol", new Symbol("Test")); o.put("ObjectId", org.bson.types.ObjectId.createFromLegacyFormat( Integer.MAX_VALUE, -2, Integer.MIN_VALUE)); Pattern p = Pattern.compile(".*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE | Pattern.UNICODE_CASE); o.put("Regex", p); Map<?, ?> data = parseBsonObject(o); assertEquals(new Timestamp(0xAABB, 0xCCDD), data.get("Timestamp")); assertEquals(new de.undercouch.bson4jackson.types.Symbol("Test"), data.get("Symbol")); ObjectId oid = (ObjectId)data.get("ObjectId"); assertEquals(Integer.MAX_VALUE, oid.getTime()); assertEquals(-2, oid.getMachine()); assertEquals(Integer.MIN_VALUE, oid.getInc()); Pattern p2 = (Pattern)data.get("Regex"); assertEquals(p.flags(), p2.flags()); assertEquals(p.pattern(), p2.pattern()); }
} else if (value instanceof Symbol) { Symbol symbol = (Symbol)value; value = new org.bson.types.Symbol(symbol.getSymbol()); } else if (value instanceof ObjectId) { ObjectId id = (ObjectId)value;