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


Java BsonDocument.parse方法代码示例

本文整理汇总了Java中org.bson.BsonDocument.parse方法的典型用法代码示例。如果您正苦于以下问题:Java BsonDocument.parse方法的具体用法?Java BsonDocument.parse怎么用?Java BsonDocument.parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bson.BsonDocument的用法示例。


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

示例1: convertBinaryUUID

import org.bson.BsonDocument; //导入方法依赖的package包/类
/**
 * Converts a binary uuid to a standard uuid
 *
 * @param json The json string (should contain "$binary" and "$type" or something like that)
 * @return The uuid
 */
private UUID convertBinaryUUID(String key, String json) {
    BsonDocument document = BsonDocument.parse(json);

    BsonValue value = document.get(key);
    if(!(value instanceof BsonBinary)) {
        return null;
    }
    byte[] bytes = ((BsonBinary) value).getData();
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    long l1 = bb.getLong();
    long l2 = bb.getLong();

    return new UUID(l1, l2);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:22,代码来源:DbFilter.java

示例2: withFlagReplaceShouldTreatMissingValuesAsNull

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void withFlagReplaceShouldTreatMissingValuesAsNull() throws IOException {
	BsonDocument source = BsonDocument.parse("{\"a\":\"test\"}");
	BsonDocument expected = BsonDocument.parse("{\"a\":null}");
	BsonDocument result = BsonPatch.apply(replaceNodeWithMissingValue, source, EnumSet.of(MISSING_VALUES_AS_NULLS)).asDocument();
    assertThat(result, equalTo(expected));
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:8,代码来源:CompatibilityTest.java

示例3: withFlagIgnoreRemoveNoneExistingArrayElement

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void withFlagIgnoreRemoveNoneExistingArrayElement() throws IOException {
	BsonDocument source = BsonDocument.parse("{\"b\": []}");
	BsonDocument expected = BsonDocument.parse("{\"b\": []}");
	BsonDocument result = BsonPatch.apply(removeNoneExistingArrayElement, source, EnumSet.of(REMOVE_NONE_EXISTING_ARRAY_ELEMENT)).asDocument();
	assertThat(result, equalTo(expected));
 }
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:8,代码来源:CompatibilityTest.java

示例4: testMoveValueGeneratedHasNoValue

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testMoveValueGeneratedHasNoValue() throws IOException {
    BsonValue jsonNode1 = BsonDocument.parse("{ \"foo\": { \"bar\": \"baz\", \"waldo\": \"fred\" }, \"qux\": { \"corge\": \"grault\" } }");
    BsonValue jsonNode2 = BsonDocument.parse("{ \"foo\": { \"bar\": \"baz\" }, \"qux\": { \"corge\": \"grault\", \"thud\": \"fred\" } }");
    BsonArray patch = BsonArray.parse("[{\"op\":\"move\",\"from\":\"/foo/waldo\",\"path\":\"/qux/thud\"}]");

    BsonArray diff = BsonDiff.asBson(jsonNode1, jsonNode2);

    assertThat(diff, equalTo(patch));
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:11,代码来源:MoveOperationTest.java

示例5: testMoveArrayGeneratedHasNoValue

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testMoveArrayGeneratedHasNoValue() throws IOException {
	BsonValue jsonNode1 = BsonDocument.parse("{ \"foo\": [ \"all\", \"grass\", \"cows\", \"eat\" ] }");
	BsonValue jsonNode2 = BsonDocument.parse("{ \"foo\": [ \"all\", \"cows\", \"eat\", \"grass\" ] }");
    BsonArray patch = BsonArray.parse("[{\"op\":\"move\",\"from\":\"/foo/1\",\"path\":\"/foo/3\"}]");

    BsonArray diff = BsonDiff.asBson(jsonNode1, jsonNode2);

    assertThat(diff, equalTo(patch));
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:11,代码来源:MoveOperationTest.java

示例6: withFlagAddShouldTreatMissingValuesAsNulls

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void withFlagAddShouldTreatMissingValuesAsNulls() throws IOException {
    BsonDocument expected = BsonDocument.parse("{\"a\":null}");
    BsonDocument result = BsonPatch.apply(addNodeWithMissingValue, new BsonDocument(), EnumSet.of(MISSING_VALUES_AS_NULLS)).asDocument();
    assertThat(result, equalTo(expected));
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:7,代码来源:CompatibilityTest.java

示例7: applyingNonArrayPatchShouldThrowAnException

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test(expected = InvalidBsonPatchException.class)
public void applyingNonArrayPatchShouldThrowAnException() throws IOException {
	BsonArray invalid = BsonArray.parse("[\"not\", \"a patch\"]");
	BsonDocument to = BsonDocument.parse("{\"a\":1}");
    BsonPatch.apply(invalid, to);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:7,代码来源:ApiTest.java

示例8: applyingAnInvalidArrayShouldThrowAnException

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test(expected = InvalidBsonPatchException.class)
public void applyingAnInvalidArrayShouldThrowAnException() throws IOException {
	BsonArray invalid = BsonArray.parse("[1, 2, 3, 4, 5]");
	BsonDocument to = BsonDocument.parse("{\"a\":1}");
    BsonPatch.apply(invalid, to);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:7,代码来源:ApiTest.java

示例9: applyingAPatchWithAnInvalidOperationShouldThrowAnException

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test(expected = InvalidBsonPatchException.class)
public void applyingAPatchWithAnInvalidOperationShouldThrowAnException() throws IOException {
	BsonArray invalid = BsonArray.parse("[{\"op\": \"what\"}]");
	BsonDocument to = BsonDocument.parse("{\"a\":1}");
    BsonPatch.apply(invalid, to);
}
 
开发者ID:eBay,项目名称:bsonpatch,代码行数:7,代码来源:ApiTest.java

示例10: encode

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Override
public BsonJavaScriptWithScope encode(CodeWithScope object) {
    return new BsonJavaScriptWithScope(object.getCode(), BsonDocument.parse(object.getScope().toJson()));
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:5,代码来源:BsonCodeWithScopeConverter.java


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