本文整理匯總了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()));
}