本文整理汇总了Java中io.datatree.dom.TreeWriter类的典型用法代码示例。如果您正苦于以下问题:Java TreeWriter类的具体用法?Java TreeWriter怎么用?Java TreeWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreeWriter类属于io.datatree.dom包,在下文中一共展示了TreeWriter类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBinaryConverter
import io.datatree.dom.TreeWriter; //导入依赖的package包/类
@Test
public void testBinaryConverter() throws Exception {
Class<? extends TreeWriter> writerClass = TreeWriterRegistry.getWriter(TreeWriterRegistry.JSON).getClass();
if (writerClass == JsonSimple.class || writerClass == JsonJsonIO.class) {
// JSONSimple and JsonIO cant serialize (Object) arrays
return;
}
testConverter("abcdefghijkl", byte[].class);
testConverter("abcdefghijkl".getBytes(), byte[].class);
testConverter(new Tree("[1,2,3,4,5]").asObject(), byte[].class);
testConverter((byte) 123, byte[].class);
testConverter((short) 1234, byte[].class);
testConverter((float) 1234.5678, byte[].class);
testConverter((double) 1234.5678, byte[].class);
testConverter(1234, byte[].class);
testConverter(123456789L, byte[].class);
testConverter(new BigDecimal("1234.5678"), byte[].class);
testConverter(new BigInteger("12345678"), byte[].class);
testConverter(true, byte[].class);
testConverter(false, byte[].class);
testConverter(InetAddress.getLocalHost(), byte[].class);
testConverter(UUID.randomUUID(), byte[].class);
testConverter(new Date(), byte[].class);
}
示例2: testStringConverter
import io.datatree.dom.TreeWriter; //导入依赖的package包/类
@Test
public void testStringConverter() throws Exception {
testConverter("abcdefghijkl", String.class);
Class<? extends TreeWriter> writerClass = TreeWriterRegistry.getWriter(TreeWriterRegistry.JSON).getClass();
if (writerClass != JsonSimple.class) {
// JSONSimple doesn't serialize (Object) arrays
testConverter("abcdefghijkl".getBytes(), String.class);
}
testConverter((byte) 123, String.class);
testConverter((short) 1234, String.class);
testConverter((float) 1234.5678, String.class);
testConverter((double) 1234.5678, String.class);
testConverter(1234, String.class);
if (writerClass != JsonSimple.class) {
testConverter(123456789L, byte[].class);
}
testConverter(new BigDecimal("1234.5678"), String.class);
testConverter(new BigInteger("12345678"), String.class);
testConverter(true, String.class);
testConverter(false, String.class);
if (writerClass != JsonSimple.class) {
testConverter(InetAddress.getLocalHost(), String.class);
testConverter(UUID.randomUUID(), String.class);
testConverter(new Date(), String.class);
}
}
示例3: removeFormatting
import io.datatree.dom.TreeWriter; //导入依赖的package包/类
private static final String removeFormatting(String txt) {
Class<? extends TreeWriter> writerClass = TreeWriterRegistry.getWriter(TreeWriterRegistry.JSON).getClass();
if (writerClass == JsonIon.class) {
txt = txt.replace("\"", "");
txt = txt.replace("e0,", ",");
}
return txt.replace("\t", " ").replace("\r", " ").replace("\n", " ").replace(" ", "").replace(".0", "");
}
示例4: testPutToArray
import io.datatree.dom.TreeWriter; //导入依赖的package包/类
public void testPutToArray() throws Exception {
Tree t = new Tree();
t.putList("a").add(1).add(2).add(3);
t.put("a[3]", 4);
assertJsonEquals("{\"a\":[1,2,3,4]}", t.toString(false));
t.put("a[2]", 5);
assertJsonEquals("{\"a\":[1,2,5,4]}", t.toString(false));
t.putList("a").add(1).add(2).add(3);
t.get("a[0]").remove();
assertJsonEquals("{\"a\":[2,3]}", t.toString(false));
t.get("a").getLastChild().remove();
assertJsonEquals("{\"a\":[2]}", t.toString(false));
Class<? extends TreeWriter> writerClass = TreeWriterRegistry.getWriter(TreeWriterRegistry.JSON).getClass();
if (writerClass != JsonJohnzon.class) {
t.put("a[3]", 4);
assertJsonEquals("{\"a\":[2,null,null,4]}", t.toString(false));
}
t.putObject("a", new int[] { 1, 2, 3 });
t.put("a[3]", 4);
assertJsonEquals("{\"a\":[1,2,3,4]}", t.toString(false));
t.put("a[2]", 5);
assertJsonEquals("{\"a\":[1,2,5,4]}", t.toString(false));
if (writerClass != JsonSimple.class) {
// JSONSimple doesn't serialize arrays
t.putObject("a", new int[] { 1, 2, 3 });
t.get("a[0]").remove();
assertJsonEquals("{\"a\":[2,3]}", t.toString(false));
t.get("a").getLastChild().remove();
assertJsonEquals("{\"a\":[2]}", t.toString(false));
if (writerClass != JsonJohnzon.class) {
// Johnzon bug
t.put("a[3]", 4);
assertJsonEquals("{\"a\":[2,null,null,4]}", t.toString(false));
}
t.putObject("a", new int[] { 1, 2, 3 });
t.get("a").remove((child) -> {
return child.asInteger() == 2;
});
assertJsonEquals("{\"a\":[1,3]}", t.toString(false));
}
if (writerClass != JsonJohnzon.class) {
// Johnzon bug
t.putObject("a", new int[] { 1 });
t.put("a[3]", "b");
assertJsonEquals("{\"a\":[1,null,null,\"b\"]}", t.toString(false));
}
t.putObject("a", new int[] { 1, 2, 3 });
t.get("a").add(true);
assertJsonEquals("{\"a\":[1,2,3,true]}", t.toString(false));
t.putMap("a").put("b", "c");
assertJsonEquals("{\"a\":{\"b\":\"c\"}}", t.toString(false));
t.get("a").add(true);
assertJsonEquals("{\"a\":[\"c\",true]}", t.toString(false));
}