Java 类org.bson.BsonDecimal128 实例源码

项目:immutables    文件:BsonDecimal128Test.java   
@Test
public void read() throws Exception {
  BsonDocument doc = new BsonDocument();
  doc.put("int", new BsonDecimal128(Decimal128.parse(Integer.toString(Integer.MAX_VALUE))));
  doc.put("long", new BsonDecimal128(new Decimal128(Long.MAX_VALUE)));
  doc.put("double", new BsonDecimal128(Decimal128.parse("12.111")));

  JsonReader reader =  Jsons.asGsonReader(doc);

  reader.beginObject();
  check(reader.nextName()).is("int");
  check(reader.peek()).is(JsonToken.NUMBER);
  check(reader.nextInt()).is(Integer.MAX_VALUE);

  check(reader.nextName()).is("long");
  check(reader.peek()).is(JsonToken.NUMBER);
  check(reader.nextLong()).is(Long.MAX_VALUE);

  check(reader.nextName()).is("double");
  check(reader.peek()).is(JsonToken.NUMBER);
  check(reader.nextDouble()).is(12.111D);

  reader.endObject();

  reader.close();
}
项目:BsonMapper    文件:BsonBigDecimalConverter.java   
@Override
public BsonDecimal128 encode(BigDecimal object) {
    return new BsonDecimal128(new Decimal128(object));
}