本文整理汇总了Java中org.ojai.json.Json.newDocumentBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Json.newDocumentBuilder方法的具体用法?Java Json.newDocumentBuilder怎么用?Java Json.newDocumentBuilder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ojai.json.Json
的用法示例。
在下文中一共展示了Json.newDocumentBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDocumentPut
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testDocumentPut() {
Document document = Json.newDocument();
document.set("recValue1", "string");
document.set("recValue2", 1);
Document document2 = Json.newDocument();
document2.set("val1", true);
document2.set("val2", 100);
List<Object> l = new ArrayList<Object>();
l.add("abcd");
l.add(false);
document2.set("list", l);
document.set("rec", document2);
DocumentBuilder documentBuilder = Json.newDocumentBuilder();
documentBuilder.addNewMap();
documentBuilder.put("document", document);
documentBuilder.put("rootValue1", 1)
.put("rootValue2", "2").endMap();
logger.info(documentBuilder.toString());
}
示例2: testPutMapUsingBuilder
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testPutMapUsingBuilder() {
JsonDocumentBuilder w = (JsonDocumentBuilder)Json.newDocumentBuilder();
w.addNewMap();
w.putNull("a1");
Map<String, Object> m = new HashMap<String, Object>();
m.put("k1", "abcd");
m.put("k2", Arrays.asList(1, 2, 3));
Map<String, Object> m2 = new HashMap<String, Object>();
m2.put("k3", ODate.parse("2005-10-22"));
m2.put("k4", Arrays.asList(1.111, 2.222, 3.333));
m.put("k5", m2);
w.put("map", m);
w.endMap();
Document r = w.getDocument();
logger.info(w.asUTF8String());
assertEquals(2, r.getInt("map.k2[1]"));
}
示例3: testArrayWithinArray
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testArrayWithinArray() {
JsonDocumentBuilder w = (JsonDocumentBuilder)Json.newDocumentBuilder();
w.addNewMap();
w.putNewArray("array");
w.add("abcd");
Document r = Json.newDocument();
List<Object> l = new ArrayList<Object>();
l.add(123);
l.add(456);
r.set("list", l);
w.add(r.getValue("list"));
w.endArray();
w.endMap();
r = w.getDocument();
assertEquals(456, r.getInt("array[1][1]"));
}
示例4: write
import org.ojai.json.Json; //导入方法依赖的package包/类
@Override
public void write(LongWritable arg0, Document document) throws IOException,
InterruptedException {
writer = (JsonDocumentBuilder) Json.newDocumentBuilder();
DocumentReader reader = document.asReader();
Json.writeReaderToBuilder(reader, writer);
byte[] bytes = writer.getOutputStream();
out.write(bytes);
}
示例5: testJsonSerialization
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testJsonSerialization() throws Exception {
try (InputStream in = getJsonStream("multidocument.json");
DocumentStream stream = Json.newDocumentStream(in)) {
for (DocumentReader reader : stream.documentReaders()) {
DocumentBuilder builder = Json.newDocumentBuilder();
Documents.writeReaderToBuilder(reader, builder);
logger.info(builder.toString());
}
}
}
示例6: testWrongEndmap
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testWrongEndmap() {
DocumentBuilder builder = Json.newDocumentBuilder();
builder.addNewMap();
builder.put("string", "santanu");
builder.endMap();
exception.expect(IllegalStateException.class);
builder.endMap();
}
示例7: TestWrongMapInsertion
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void TestWrongMapInsertion() {
DocumentBuilder builder = Json.newDocumentBuilder();
builder.addNewMap();
builder.putNewArray("array");
builder.add((short) 1000);
exception.expect(IllegalStateException.class);
builder.put("string", "value");
}
示例8: testWrongArrayInsertion
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testWrongArrayInsertion() {
DocumentBuilder builder = Json.newDocumentBuilder();
builder.addNewMap();
builder.put("a", "abcd");
exception.expect(IllegalStateException.class);
builder.add(1234);
}
示例9: testWrongArrayInitiation
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testWrongArrayInitiation() {
DocumentBuilder builder = Json.newDocumentBuilder();
builder.addNewMap();
builder.put("a", "abcd");
exception.expect(IllegalStateException.class);
builder.addNewArray();
}
示例10: testPutNewMapInArray
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testPutNewMapInArray() {
DocumentBuilder w = Json.newDocumentBuilder();
w.addNewMap();
w.put("a", "abc");
w.putNewArray("array");
w.add(1.111);
exception.expect(IllegalStateException.class);
w.putNewMap("map");
}
示例11: testExceptionForIncompleteDocument
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testExceptionForIncompleteDocument() {
JsonDocumentBuilder w = (JsonDocumentBuilder)Json.newDocumentBuilder();
w.addNewMap();
w.put("f1", "abcd");
exception.expect(IllegalStateException.class);
Document r = w.getDocument();
assertNotNull(r);
}
示例12: testPutListAsValue
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unused")
public void testPutListAsValue() {
DocumentBuilder jsonDocumentBuilder = Json.newDocumentBuilder();
jsonDocumentBuilder.addNewMap();
List<Object> list = new ArrayList<>();
list.add(1);
list.add("2");
Value v = JsonValueBuilder.initFrom(list);
jsonDocumentBuilder.put("value", v);
jsonDocumentBuilder.endMap();
Document r = jsonDocumentBuilder.getDocument();
}
示例13: TestDecimalRange
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void TestDecimalRange() {
DocumentBuilder builder = Json.newDocumentBuilder();
builder.addNewMap();
builder.putDecimal("d1", Integer.MAX_VALUE, 7);
builder.putDecimal("d2", Integer.MIN_VALUE, 7);
builder.putDecimal("d3", Long.MAX_VALUE, 9);
builder.putDecimal("d4", Long.MIN_VALUE, 9);
builder.putDecimal("d5", Integer.MAX_VALUE, 15);
builder.putDecimal("d6", Integer.MIN_VALUE, 15);
builder.putDecimal("d7", Long.MAX_VALUE, 25);
builder.putDecimal("d8", Long.MIN_VALUE, 25);
builder.endMap();
logger.info(builder.toString());
}
示例14: testDocumentAdd
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testDocumentAdd() {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("null", null);
map.put("boolean", true);
map.put("string", "eureka");
List<Object> l = new ArrayList<Object>();
l.add("test1");
Map<String, Object> m2 = new LinkedHashMap<String, Object>();
m2.put("int", 32900);
l.add(m2);
l.add(Long.valueOf("9223372036854775807").longValue());
l.add(new BigDecimal(7126353.167263));
map.put("array", l);
Document innerDocument = Json.newDocument();
innerDocument.set("map", map);
//assert on integer field inside innerDocument
assertEquals(32900, innerDocument.getInt("map.array[1].int"));
JsonDocumentBuilder builder = (JsonDocumentBuilder)Json.newDocumentBuilder();
builder.addNewMap();
builder.putNewMap("map");
builder.putNewArray("array");
builder.add(innerDocument);
builder.add(true);
builder.endArray();
builder.endMap();
builder.endMap();
Document rec = builder.getDocument();
//rerun assert on built document
assertEquals(32900, rec.getInt("map.array[0].map.array[1].int"));
logger.info(builder.asUTF8String());
}
示例15: testArrayAndMapWithinMap
import org.ojai.json.Json; //导入方法依赖的package包/类
@Test
public void testArrayAndMapWithinMap() {
JsonDocumentBuilder w = (JsonDocumentBuilder)Json.newDocumentBuilder();
w.addNewMap();
w.putNewArray("array");
w.add("abcd");
Document r = Json.newDocument();
List<Object> l = new ArrayList<Object>();
l.add(123);
l.add(456);
r.set("list", l);
w.add(r.getValue("list"));
w.endArray();
Map<String, Object> m = new HashMap<String, Object>();
Map<String, Object> m2 = new HashMap<String, Object>();
m2.put("a1", true);
m2.put("a2", 11.456);
List<Object> ll = new ArrayList<Object>();
ll.add(new BigDecimal(111.11111));
m2.put("arr2",ll);
m.put("a3", 5555);
m.put("map", m2);
w.put("f", m);
w.endMap();
r = w.getDocument();
assertEquals(5555, r.getInt("f.a3"));
assertEquals(true, r.getBoolean("f.map.a1"));
}