@Override public void encode(final BsonWriter writer, final Symbol value, final EncoderContext encoderContext) { writer.writeSymbol(value.getSymbol()); }
/** * Encodes a Symbol field * * @param name the field name * @param symbol the value * @see org.bson.BsonType#SYMBOL */ protected void putSymbol(final String name, final Symbol symbol) { putName(name); bsonWriter.writeSymbol(symbol.getSymbol()); }
@SuppressWarnings("unchecked") private void writeValue(final BsonWriter bsonWriter, final EncoderContext encoderContext, final Object initialValue) { Object value = org.bson.BSON.applyEncodingHooks(initialValue); if (value == null) { bsonWriter.writeNull(); } else if (value instanceof DBRef) { encodeDBRef(bsonWriter, (DBRef) value); } else if (value instanceof Map) { encodeMap(bsonWriter, (Map<String, Object>) value); } else if (value instanceof Iterable) { encodeIterable(bsonWriter, (Iterable) value); } else if (value instanceof BSONObject) { encodeBsonObject(bsonWriter, ((BSONObject) value)); } else if (value instanceof CodeWScope) { encodeCodeWScope(bsonWriter, (CodeWScope) value); } else if (value instanceof byte[]) { encodeByteArray(bsonWriter, (byte[]) value); } else if (value.getClass().isArray()) { encodeArray(bsonWriter, value); } else if (value instanceof Symbol) { bsonWriter.writeSymbol(((Symbol) value).getSymbol()); } else { Codec codec = codecRegistry.get(value.getClass()); codec.encode(bsonWriter, value, encoderContext); } }
protected void putSymbol(String name, Symbol symbol) { this._putString(name, symbol.getSymbol(), 14); }
protected void putSymbol(String name, Symbol s) { _putString(name, s.getSymbol(), SYMBOL); }
@Override public void serialize(Object obj, StringBuilder buf) { Symbol s = (Symbol) obj; BasicBSONObject temp = new BasicBSONObject(); temp.put("$symbol", s.getSymbol()); serializer.serialize(temp, buf); }
return ((Symbol) value).getSymbol();
@SuppressWarnings("unchecked") private void writeValue(final BsonWriter bsonWriter, final EncoderContext encoderContext, final Object initialValue) { Object value = org.bson.BSON.applyEncodingHooks(initialValue); if (value == null) { bsonWriter.writeNull(); } else if (value instanceof DBRef) { encodeDBRef(bsonWriter, (DBRef) value); } else if (value instanceof Map) { encodeMap(bsonWriter, (Map<String, Object>) value); } else if (value instanceof Iterable) { encodeIterable(bsonWriter, (Iterable) value); } else if (value instanceof BSONObject) { encodeBsonObject(bsonWriter, ((BSONObject) value)); } else if (value instanceof CodeWScope) { encodeCodeWScope(bsonWriter, (CodeWScope) value); } else if (value instanceof byte[]) { encodeByteArray(bsonWriter, (byte[]) value); } else if (value.getClass().isArray()) { encodeArray(bsonWriter, value); } else if (value instanceof Symbol) { bsonWriter.writeSymbol(((Symbol) value).getSymbol()); } else { Codec codec = codecRegistry.get(value.getClass()); codec.encode(bsonWriter, value, encoderContext); } }
/** * 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()); }