本文整理汇总了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);
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
示例10: encode
import org.bson.BsonDocument; //导入方法依赖的package包/类
@Override
public BsonJavaScriptWithScope encode(CodeWithScope object) {
return new BsonJavaScriptWithScope(object.getCode(), BsonDocument.parse(object.getScope().toJson()));
}