Package org.bson

Examples of org.bson.BSONEncoder


    public <T> Key<T> createKey(Class<T> clazz, Object id) {
        if (id instanceof Serializable)
            return createKey(clazz, (Serializable) id);

        //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does.
        BSONEncoder enc = new BasicBSONEncoder();
        return new Key<T>(clazz, enc.encode(toDBObject(id)));
    }
View Full Code Here


   
    // チャネルを通して送信
    try {
      // バッファを確保
      OutputBuffer outputBuffer = new BasicOutputBuffer();
      BSONEncoder encoder = new BSONEncoder();
      encoder.set(outputBuffer);
      // リクエスト内容を出力
      writeRequest(request, encoder, outputBuffer);
     
      // Safeリクエストの場合は、 getLastError クエリを付加
      Request getLastError = null;
View Full Code Here

     * {@inheritDoc}
     *
     * @see Writable#write(DataOutput)
     */
    public void write(final DataOutput out) throws IOException {
        BSONEncoder enc = new BasicBSONEncoder();
        BasicOutputBuffer buf = new BasicOutputBuffer();
        enc.set(buf);
        enc.putObject(doc);
        enc.done();
        buf.pipe(out);
    }
View Full Code Here

        if (id instanceof Serializable) {
            return createKey(clazz, (Serializable) id);
        }

        //TODO: cache the encoders, maybe use the pool version of the buffer that the driver does.
        final BSONEncoder enc = new BasicBSONEncoder();
        return new Key<T>(clazz, enc.encode(toDBObject(id)));
    }
View Full Code Here

    public org.bson.types.ObjectId oid;
  }
 
  private <T> T parseBsonObject(BSONObject o, Class<T> cls,
      Module... modules) throws IOException {
    BSONEncoder enc = new BasicBSONEncoder();
    byte[] b = enc.encode(o);
   
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    BsonFactory fac = new BsonFactory();
    ObjectMapper mapper = new ObjectMapper(fac);
    if (modules != null) {
View Full Code Here

  @Test
  public void parseBig() throws Exception {
    BSONObject o = new BasicBSONObject();
    o.put("Double", 5.0);
    o.put("Int32", 1234);
    BSONEncoder enc = new BasicBSONEncoder();
    byte[] b = enc.encode(o);
   
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    ObjectMapper mapper = new ObjectMapper(new BsonFactory());
    mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
    mapper.configure(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS, true);
View Full Code Here

  @Test
  public void parseUndefined() throws Exception {
    BSONObject o = new BasicBSONObject();
    o.put("Undefined", new Object());
    o.put("Int32", 5);
    BSONEncoder enc = new BasicBSONEncoder() {
      @Override
      protected boolean putSpecial(String name, Object o) {
        putUndefined(name);
        return true;
      }
    };
    byte[] b = enc.encode(o);
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    ObjectMapper mapper = new ObjectMapper(new BsonFactory());
    Map<?, ?> data = mapper.readValue(bais, Map.class);
    assertEquals(1, data.size());
    assertEquals(5, data.get("Int32"));
View Full Code Here

   
    BSONObject o1 = new BasicBSONObject();
    o1.put("Obj2", o2);
    o1.put("Obj3", o3);
   
    BSONEncoder enc = new BasicBSONEncoder();
    byte[] b = enc.encode(o1);
   
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    BsonFactory fac = new BsonFactory();
    ObjectMapper mapper = new ObjectMapper(fac);
    fac.setCodec(mapper);
View Full Code Here

  @Test
  public void parseAsText() throws Exception {
    BSONObject o = new BasicBSONObject();
    o.put("Float", 5.0f);
    o.put("Int32", 1234);
    BSONEncoder enc = new BasicBSONEncoder();
    byte[] b = enc.encode(o);
   
    ByteArrayInputStream bais = new ByteArrayInputStream(b);
    BsonFactory fac = new BsonFactory();
    BsonParser dec = fac.createParser(bais);
   
View Full Code Here

  }
 
  private static <T> T generateAndParse(Object o, Class<T> cls) throws Exception {
    BSONObject bo = new BasicBSONObject();
    bo.put("obj", o); //that's why all properties of classes in TC must be named 'obj'
    BSONEncoder encoder = new BasicBSONEncoder();
    byte[] barr = encoder.encode(bo);
   
    ByteArrayInputStream bais = new ByteArrayInputStream(barr);
   
    ObjectMapper om = new ObjectMapper(new BsonFactory());
    om.registerModule(new BsonModule());
View Full Code Here

TOP

Related Classes of org.bson.BSONEncoder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.