当前位置: 首页>>代码示例>>Java>>正文


Java BsonNull类代码示例

本文整理汇总了Java中org.bson.BsonNull的典型用法代码示例。如果您正苦于以下问题:Java BsonNull类的具体用法?Java BsonNull怎么用?Java BsonNull使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BsonNull类属于org.bson包,在下文中一共展示了BsonNull类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBsonDocument

import org.bson.BsonNull; //导入依赖的package包/类
public static BsonDocument getBsonDocument() {
    BsonDocument bsonObj = new BsonDocument().append("testDouble", new BsonDouble(20.777));
    List<BsonDocument> list = new ArrayList<BsonDocument>();
    list.add(bsonObj);
    list.add(bsonObj);
    byte[] bytes = new byte[3];
    bytes[0] = 3;
    bytes[1] = 2;
    bytes[2] = 1;
    BsonDocument bsonDocument = new BsonDocument().append("testDouble", new BsonDouble(20.99))
            .append("testString", new BsonString("testStringV"))
            .append("testArray", new BsonArray(list));
    return new BsonDocument().append("testDouble", new BsonDouble(20.99))
            .append("testString", new BsonString("testStringV"))
            .append("testArray", new BsonArray(list))
            .append("bson_test", bsonDocument)
            .append("testBinary", new BsonBinary(bytes))
            .append("testBsonUndefined", new BsonUndefined())
            .append("testObjectId", new BsonObjectId())
            .append("testStringObjectId", new BsonObjectId())
            .append("testBoolean", new BsonBoolean(true))
            .append("testDate", new BsonDateTime(time))
            .append("testNull", new BsonNull())
            .append("testInt", new BsonInt32(233))
            .append("testLong", new BsonInt64(233332));
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:27,代码来源:TestUtil.java

示例2: toBson

import org.bson.BsonNull; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> BsonValue toBson(Object value, Class<T> clazz) {
	if(value == null) {
		return new BsonNull();
	}
	if(value instanceof BsonValue) {
		return (BsonValue) value;
	}
	final Codec<T> codec = registry.get(clazz);
	final String key = "value";
	final BsonDocument document = new BsonDocument();
	final BsonWriter writer = new BsonDocumentWriter(document);
	writer.writeStartDocument();
	writer.writeName(key);
	codec.encode(writer, (T) value, EncoderContext.builder().build());
	writer.writeEndDocument();
	return document.get(key);
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:19,代码来源:SmofParser.java

示例3: fromGridRef

import org.bson.BsonNull; //导入依赖的package包/类
private BsonValue fromGridRef(SmofGridRef fileRef, PrimaryField fieldOpts) {
	if(fileRef.isEmpty()) {
		return new BsonNull();
	}
	if(fileRef.getId() == null) {
		final SmofObject annotation = fieldOpts.getSmofAnnotationAs(SmofObject.class);
		if(fileRef.getBucketName() == null) {
			fileRef.setBucketName(annotation.bucketName());
		}
		//TODO test if upload file adds id to fileRef
		if(!annotation.preInsert() && !fieldOpts.isForcePreInsert()) {
			return new BsonLazyObjectId(fieldOpts.getName(), fileRef);
		}
		fieldOpts.setForcePreInsert(false);
		dispatcher.insert(fileRef);
	}
	final BsonDocument bsonRef = new BsonDocument("id", new BsonObjectId(fileRef.getId()))
			.append("bucket", new BsonString(fileRef.getBucketName()));
	return bsonRef;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:21,代码来源:ObjectParser.java

示例4: getTimestamps

import org.bson.BsonNull; //导入依赖的package包/类
/**
 * Return non-redundant timestamps of all graph element events
 * 
 * @return HashSet<Long> timestamps
 */
public TreeSet<Long> getTimestamps() {
	TreeSet<Long> timestampSet = new TreeSet<Long>();

	Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() {
		@Override
		public Long apply(BsonDateTime val) {
			return val.getValue();
		}

	};
	edgeEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
			.filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(timestampSet);
	Set<Long> vtSet = new TreeSet<Long>();

	vertexEvents.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
			.filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(vtSet);
	timestampSet.addAll(vtSet);

	return timestampSet;
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:28,代码来源:ChronoGraph.java

示例5: getTimestampsHashSet

import org.bson.BsonNull; //导入依赖的package包/类
public HashSet<Long> getTimestampsHashSet() {
	HashSet<Long> timestampSet = new HashSet<Long>();

	Function<BsonDateTime, Long> mapper = new Function<BsonDateTime, Long>() {
		@Override
		public Long apply(BsonDateTime val) {
			return val.getValue();
		}

	};
	edges.distinct(Tokens.TIMESTAMP, BsonDateTime.class)
			.filter(new BsonDocument(Tokens.TIMESTAMP, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(timestampSet);

	return timestampSet;
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:17,代码来源:ChronoGraph.java

示例6: removeProperty

import org.bson.BsonNull; //导入依赖的package包/类
/**
 * Un-assigns a key/value property from the element. The object value of the
 * removed property is returned.
 *
 * @param key
 *            the key of the property to remove from the element
 * @return the object value associated with that key prior to removal. Should be
 *         instance of BsonValue
 */
@Override
public <T> T removeProperty(final String key) {
	try {
		BsonValue value = getProperty(key);
		BsonDocument filter = new BsonDocument();
		filter.put(Tokens.ID, new BsonString(this.id));
		BsonDocument update = new BsonDocument();
		update.put("$unset", new BsonDocument(key, new BsonNull()));
		if (this instanceof ChronoVertex) {
			graph.getVertexCollection().updateOne(filter, update, new UpdateOptions().upsert(true));
			return (T) value;
		} else {
			graph.getEdgeCollection().updateOne(filter, update, new UpdateOptions().upsert(true));
			return (T) value;
		}
	} catch (MongoWriteException e) {
		throw e;
	}
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:29,代码来源:ChronoElement.java

示例7: bsonToGson

import org.bson.BsonNull; //导入依赖的package包/类
/**
 * Reading from BSON to GSON
 */
@Test
public void bsonToGson() throws Exception {
    BsonDocument document = new BsonDocument();
    document.append("boolean", new BsonBoolean(true));
    document.append("int32", new BsonInt32(32));
    document.append("int64", new BsonInt64(64));
    document.append("double", new BsonDouble(42.42D));
    document.append("string", new BsonString("foo"));
    document.append("null", new BsonNull());
    document.append("array", new BsonArray());
    document.append("object", new BsonDocument());

    JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document)));
    check(element.isJsonObject());

    check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean());
    check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean());

    check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber());
    check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32);

    check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber());
    check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L);

    check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber());
    check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D);

    check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString());
    check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo");

    check(element.getAsJsonObject().get("null").isJsonNull());
    check(element.getAsJsonObject().get("array").isJsonArray());
    check(element.getAsJsonObject().get("object").isJsonObject());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:BsonReaderTest.java

示例8: testNullType

import org.bson.BsonNull; //导入依赖的package包/类
@Test
public void testNullType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("nullKey", new BsonNull());
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals(null, mapReader.reader("nullKey").readObject());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java

示例9: getChronoVertices

import org.bson.BsonNull; //导入依赖的package包/类
/**
 * Return an iterable to all the vertices in the graph. If this is not possible
 * for the implementation, then an UnsupportedOperationException can be thrown.
 *
 * @return an iterable reference to all vertices in the graph
 */
public Iterable<ChronoVertex> getChronoVertices() {
	HashSet<String> idSet = new HashSet<String>();
	Function<BsonString, String> mapper = new Function<BsonString, String>() {
		@Override
		public String apply(BsonString val) {
			return val.getValue();
		}

	};
	HashSet<String> outV = new HashSet<String>();
	edges.distinct(Tokens.OUT_VERTEX, BsonString.class)
			.filter(new BsonDocument(Tokens.OUT_VERTEX, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(outV);
	idSet.addAll(outV);
	HashSet<String> inV = new HashSet<String>();
	edges.distinct(Tokens.IN_VERTEX, BsonString.class)
			.filter(new BsonDocument(Tokens.IN_VERTEX, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(inV);
	idSet.addAll(inV);

	MongoCursor<BsonDocument> vi = vertices.find(Tokens.FLT_VERTEX_FIELD_NOT_INCLUDED)
			.projection(Tokens.PRJ_ONLY_ID).iterator();
	while (vi.hasNext()) {
		BsonDocument d = vi.next();
		idSet.add(d.getString(Tokens.ID).getValue());
	}

	HashSet<String> vertex = new HashSet<String>();
	vertices.distinct(Tokens.VERTEX, BsonString.class)
			.filter(new BsonDocument(Tokens.VERTEX, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(vertex);
	idSet.addAll(vertex);

	return idSet.parallelStream().map(s -> new ChronoVertex(s, this)).collect(Collectors.toSet());
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:42,代码来源:ChronoGraph.java

示例10: getChronoVertexStream

import org.bson.BsonNull; //导入依赖的package包/类
/**
 * Return an iterable to all the vertices in the graph. If this is not possible
 * for the implementation, then an UnsupportedOperationException can be thrown.
 *
 * @return an iterable reference to all vertices in the graph
 */
public Stream<ChronoVertex> getChronoVertexStream(boolean isParallel) {
	HashSet<String> idSet = new HashSet<String>();
	Function<BsonString, String> mapper = new Function<BsonString, String>() {
		@Override
		public String apply(BsonString val) {
			return val.getValue();
		}

	};
	HashSet<String> outV = new HashSet<String>();
	edges.distinct(Tokens.OUT_VERTEX, BsonString.class)
			.filter(new BsonDocument(Tokens.OUT_VERTEX, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(outV);
	idSet.addAll(outV);
	HashSet<String> inV = new HashSet<String>();
	edges.distinct(Tokens.IN_VERTEX, BsonString.class)
			.filter(new BsonDocument(Tokens.IN_VERTEX, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(inV);
	idSet.addAll(inV);

	MongoCursor<BsonDocument> vi = vertices.find(Tokens.FLT_VERTEX_FIELD_NOT_INCLUDED)
			.projection(Tokens.PRJ_ONLY_ID).iterator();
	while (vi.hasNext()) {
		BsonDocument d = vi.next();
		idSet.add(d.getString(Tokens.ID).getValue());
	}

	HashSet<String> vertex = new HashSet<String>();
	vertices.distinct(Tokens.VERTEX, BsonString.class)
			.filter(new BsonDocument(Tokens.VERTEX, new BsonDocument(Tokens.FC.$ne.toString(), new BsonNull())))
			.map(mapper).into(vertex);
	idSet.addAll(vertex);
	if (isParallel)
		return idSet.parallelStream().map(s -> new ChronoVertex(s, this)).collect(Collectors.toSet())
				.parallelStream();
	else
		return idSet.parallelStream().map(s -> new ChronoVertex(s, this)).collect(Collectors.toSet()).stream();
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:45,代码来源:ChronoGraph.java

示例11: transform

import org.bson.BsonNull; //导入依赖的package包/类
@Override
public void transform(
        HttpServerExchange exchange,
        RequestContext context,
        BsonValue contentToTransform,
        BsonValue args) {
    if (context.getDbOperationResult() == null) {
    } else {
        BsonDocument resp = null;

        if (contentToTransform == null || !contentToTransform.isDocument()) {
            resp = new BsonDocument();
            context.setResponseContent(resp);
        } else if (contentToTransform.isDocument()) {
            resp = contentToTransform.asDocument();
        }

        if (resp != null) {
            resp.append("oldData", context.getDbOperationResult().getOldData()
                    == null
                            ? new BsonNull()
                            : context.getDbOperationResult().getOldData());

            resp.append("newData", context.getDbOperationResult().getNewData()
                    == null
                            ? new BsonNull()
                            : context.getDbOperationResult().getNewData());
        }
    }
}
 
开发者ID:SoftInstigate,项目名称:restheart,代码行数:31,代码来源:WriteResultTransformer.java

示例12: bsonToGson

import org.bson.BsonNull; //导入依赖的package包/类
/**
 * Reading from BSON to GSON
 */
@Test
public void bsonToGson() throws Exception {
  BsonDocument document = new BsonDocument();
  document.append("boolean", new BsonBoolean(true));
  document.append("int32", new BsonInt32(32));
  document.append("int64", new BsonInt64(64));
  document.append("double", new BsonDouble(42.42D));
  document.append("string", new BsonString("foo"));
  document.append("null", new BsonNull());
  document.append("array", new BsonArray());
  document.append("object", new BsonDocument());

  JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document)));
  check(element.isJsonObject());

  check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean());
  check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean());

  check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber());
  check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32);

  check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber());
  check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L);

  check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber());
  check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D);

  check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString());
  check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo");

  check(element.getAsJsonObject().get("null").isJsonNull());
  check(element.getAsJsonObject().get("array").isJsonArray());
  check(element.getAsJsonObject().get("object").isJsonObject());
}
 
开发者ID:immutables,项目名称:immutables,代码行数:38,代码来源:BsonReaderTest.java

示例13: accept

import org.bson.BsonNull; //导入依赖的package包/类
@Override
public void accept(ObjectMapper mapper) {
	SimpleModule module = new SimpleModule();

	addSerializer(module, BsonBoolean.class, (value, gen) -> {
		gen.writeBoolean(value.getValue());
	});

	addSerializer(module, BsonDateTime.class, (value, gen) -> {
		if (Config.USE_TIMESTAMPS) {
			gen.writeString(DataConverterRegistry.convert(String.class, new Date(value.getValue())));
		} else {
			gen.writeNumber(value.getValue());
		}
	});

	addSerializer(module, BsonDouble.class, (value, gen) -> {
		gen.writeNumber(value.getValue());
	});

	addSerializer(module, BsonInt32.class, (value, gen) -> {
		gen.writeNumber(value.getValue());
	});

	addSerializer(module, BsonInt64.class, (value, gen) -> {
		gen.writeNumber(value.getValue());
	});

	addSerializer(module, BsonNull.class, (value, gen) -> {
		gen.writeNull();
	});

	addSerializer(module, BsonRegularExpression.class, (value, gen) -> {
		gen.writeString(value.getPattern());
	});

	addSerializer(module, BsonString.class, (value, gen) -> {
		gen.writeString(value.getValue());
	});

	addSerializer(module, BsonTimestamp.class, (value, gen) -> {
		if (Config.USE_TIMESTAMPS) {
			gen.writeString(DataConverterRegistry.convert(String.class, new Date(value.getTime() * 1000L)));
		} else {
			gen.writeNumber(value.getTime());
		}
	});

	addSerializer(module, BsonUndefined.class, (value, gen) -> {
		gen.writeNull();
	});

	addSerializer(module, Binary.class, (value, gen) -> {
		gen.writeString(BASE64.encode(value.getData()));
	});

	addSerializer(module, Code.class, (value, gen) -> {
		gen.writeString(value.getCode());
	});

	addSerializer(module, Decimal128.class, (value, gen) -> {
		gen.writeNumber(value.bigDecimalValue());
	});

	addSerializer(module, ObjectId.class, (value, gen) -> {
		gen.writeString(value.toHexString());
	});

	addSerializer(module, Symbol.class, (value, gen) -> {
		gen.writeString(value.getSymbol());
	});

	mapper.registerModule(module);
}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:75,代码来源:JsonJacksonBsonSerializers.java

示例14: accept

import org.bson.BsonNull; //导入依赖的package包/类
@Override
public void accept(ExtensibleRepresenter representer) {

	addSerializer(representer, BsonBoolean.class, (value) -> {
		return Boolean.toString(value.getValue());
	});

	addSerializer(representer, BsonDateTime.class, (value) -> {
		if (Config.USE_TIMESTAMPS) {
			return DataConverterRegistry.convert(String.class, new Date(value.getValue()));
		}
		return Long.toString(value.getValue());
	});

	addSerializer(representer, BsonDouble.class, (value) -> {
		return Double.toString(value.getValue());
	});

	addSerializer(representer, BsonInt32.class, (value) -> {
		return Integer.toString(value.getValue());
	});

	addSerializer(representer, BsonInt64.class, (value) -> {
		return Long.toString(value.getValue());
	});

	addSerializer(representer, BsonNull.class, (value) -> {
		return null;
	});

	addSerializer(representer, BsonRegularExpression.class, (value) -> {
		return value.getPattern();
	});

	addSerializer(representer, BsonString.class, (value) -> {
		return value.getValue();
	});

	addSerializer(representer, BsonTimestamp.class, (value) -> {
		if (Config.USE_TIMESTAMPS) {
			return DataConverterRegistry.convert(String.class, new Date(value.getTime() * 1000L));
		}
		return Integer.toString(value.getTime());
	});

	addSerializer(representer, BsonUndefined.class, (value) -> {
		return null;
	});

	addSerializer(representer, Binary.class, (value) -> {
		return BASE64.encode(value.getData());
	});

	addSerializer(representer, Code.class, (value) -> {
		return value.getCode();
	});

	addSerializer(representer, Decimal128.class, (value) -> {
		return value.bigDecimalValue().toPlainString();
	});

	addSerializer(representer, ObjectId.class, (value) -> {
		return value.toHexString();
	});

	addSerializer(representer, Symbol.class, (value) -> {
		return value.getSymbol();
	});

}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:71,代码来源:YamlSnakeYamlBsonSerializers.java

示例15: accept

import org.bson.BsonNull; //导入依赖的package包/类
@Override
public void accept(MapperBuilder builder) {

	addSerializer(builder, BsonBoolean.class, Boolean.class, (value) -> {
		return value.getValue();
	});

	if (Config.USE_TIMESTAMPS) {
		addSerializer(builder, BsonDateTime.class, String.class, (value) -> {
			return DataConverterRegistry.convert(String.class, new Date(value.getValue()));
		});
	} else {
		addSerializer(builder, BsonDateTime.class, Long.class, (value) -> {
			return value.getValue();
		});
	}

	addSerializer(builder, BsonDouble.class, Double.class, (value) -> {
		return value.getValue();
	});

	addSerializer(builder, BsonInt32.class, Integer.class, (value) -> {
		return value.getValue();
	});

	addSerializer(builder, BsonInt64.class, Long.class, (value) -> {
		return value.getValue();
	});

	addSerializer(builder, BsonNull.class, Object.class, (value) -> {

		// Johnzon fails from null values
		return "null";
	});

	addSerializer(builder, BsonRegularExpression.class, String.class, (value) -> {
		return value.getPattern();
	});

	addSerializer(builder, BsonString.class, String.class, (value) -> {
		return value.getValue();
	});

	if (Config.USE_TIMESTAMPS) {
		addSerializer(builder, BsonTimestamp.class, String.class, (value) -> {
			return DataConverterRegistry.convert(String.class, new Date(value.getTime() * 1000L));
		});
	} else {
		addSerializer(builder, BsonTimestamp.class, Integer.class, (value) -> {
			return value.getTime();
		});
	}

	addSerializer(builder, BsonUndefined.class, String.class, (value) -> {

		// Johnzon fails from null values
		return "null";
	});

	addSerializer(builder, Binary.class, String.class, (value) -> {
		return BASE64.encode(value.getData());
	});

	addSerializer(builder, Code.class, String.class, (value) -> {
		return value.getCode();
	});

	addSerializer(builder, Decimal128.class, BigDecimal.class, (value) -> {
		return value.bigDecimalValue();
	});

	addSerializer(builder, ObjectId.class, String.class, (value) -> {
		return value.toHexString();
	});

	addSerializer(builder, Symbol.class, String.class, (value) -> {
		return value.getSymbol();
	});

}
 
开发者ID:berkesa,项目名称:datatree-adapters,代码行数:81,代码来源:JsonJohnzonBsonSerializers.java


注:本文中的org.bson.BsonNull类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。