當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。