本文整理了Java中org.apache.juneau.json.JsonSerializer.serialize()
方法的一些代码示例,展示了JsonSerializer.serialize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonSerializer.serialize()
方法的具体详情如下:
包路径:org.apache.juneau.json.JsonSerializer
类名称:JsonSerializer
方法名:serialize
暂无
代码示例来源:origin: org.apache.juneau/juneau-marshall
/**
* Convenience method for serializing this ObjectList to the specified Writer using the JsonSerializer.DEFAULT
* serializer.
*
* @param w The writer to send the serialized contents of this object.
* @throws IOException If a problem occurred trying to write to the writer.
* @throws SerializeException If a problem occurred trying to convert the output.
*/
public void serializeTo(Writer w) throws IOException, SerializeException {
JsonSerializer.DEFAULT.serialize(this);
}
代码示例来源:origin: apache/juneau
/**
* Convenience method for serializing this map to the specified <code>Writer</code> using the
* {@link JsonSerializer#DEFAULT} serializer.
*
* @param w The writer to serialize this object to.
* @return This object (for method chaining).
* @throws IOException If a problem occurred trying to write to the writer.
* @throws SerializeException If a problem occurred trying to convert the output.
*/
public ObjectMap serializeTo(Writer w) throws IOException, SerializeException {
JsonSerializer.DEFAULT.serialize(this);
return this;
}
代码示例来源:origin: apache/juneau
/**
* Convenience method for serializing this ObjectList to the specified Writer using the JsonSerializer.DEFAULT
* serializer.
*
* @param w The writer to send the serialized contents of this object.
* @throws IOException If a problem occurred trying to write to the writer.
* @throws SerializeException If a problem occurred trying to convert the output.
*/
public void serializeTo(Writer w) throws IOException, SerializeException {
JsonSerializer.DEFAULT.serialize(this);
}
代码示例来源:origin: cowtowncoder/java-json-performance-benchmarks
@Override
public String _writeAsString(MeasurementPOJO items) throws Exception {
return serializer.serialize(items);
}
}
代码示例来源:origin: apache/juneau
/**
* Convenience method for serializing this ObjectList to the specified Writer using the JsonSerializer.DEFAULT
* serializer.
*
* @param w The writer to send the serialized contents of this object.
* @throws IOException If a problem occurred trying to write to the writer.
* @throws SerializeException If a problem occurred trying to convert the output.
*/
public void serializeTo(Writer w) throws IOException, SerializeException {
JsonSerializer.DEFAULT.serialize(this);
}
代码示例来源:origin: org.apache.juneau/juneau-marshall
/**
* Convenience method for serializing this map to the specified <code>Writer</code> using the
* {@link JsonSerializer#DEFAULT} serializer.
*
* @param w The writer to serialize this object to.
* @return This object (for method chaining).
* @throws IOException If a problem occurred trying to write to the writer.
* @throws SerializeException If a problem occurred trying to convert the output.
*/
public ObjectMap serializeTo(Writer w) throws IOException, SerializeException {
JsonSerializer.DEFAULT.serialize(this);
return this;
}
代码示例来源:origin: cowtowncoder/java-json-performance-benchmarks
@Override
public int _writeItems(MeasurementPOJO items, Writer out) throws Exception
{
serializer.serialize(items, out);
return items.size();
}
代码示例来源:origin: cowtowncoder/java-json-performance-benchmarks
@Override
public int _writeItems(MeasurementPOJO items, OutputStream out) throws Exception
{
serializer.serialize(items, out);
return items.size();
}
代码示例来源:origin: apache/juneau
@Test
public void testSubclassedList() throws Exception {
JsonSerializer s = JsonSerializer.DEFAULT;
Map<String,Object> o = new HashMap<>();
o.put("c", new C());
assertEquals("{\"c\":[]}", s.serialize(o));
}
代码示例来源:origin: apache/juneau
@Test
public void testBeanPropertyProperiesOnListOfBeans() throws Exception {
JsonSerializer s = SimpleJsonSerializer.DEFAULT;
List<F> l = new LinkedList<>();
F t = new F();
t.x1.add(new F());
l.add(t);
String json = s.serialize(l);
assertEquals("[{x1:[{x2:2}],x2:2}]", json);
}
代码示例来源:origin: apache/juneau
@Test
public void testJson() throws Exception {
JsonSerializer s = JsonSerializer.create().ssq().pojoSwaps(ReaderSwap.Json.class).build();
Reader r;
Map<String,Object> m;
r = new StringReader("{foo:'bar',baz:'quz'}");
m = new HashMap<>();
m.put("X", r);
assertEquals("{X:{foo:'bar',baz:'quz'}}", s.serialize(m));
}
代码示例来源:origin: apache/juneau
@Test
public void testParentClassFilter() throws Exception {
JsonSerializer s = JsonSerializer.create().ssq().beanFilters(C1.class).build();
C1 c1 = new C2();
String r = s.serialize(c1);
assertEquals("{f0:'f0'}", r);
List<C1> l = new LinkedList<>();
l.add(new C2());
r = s.serialize(l);
assertEquals("[{f0:'f0'}]", r);
}
代码示例来源:origin: apache/juneau
@Test
public void testParentClassFilter2() throws Exception {
JsonSerializer s = JsonSerializer.create().ssq().beanFilters(D1.class).build();
D1 d1 = new D2();
String r = s.serialize(d1);
assertEquals("{f0:'f0'}", r);
List<D1> l = new LinkedList<>();
l.add(new D2());
r = s.serialize(l);
assertEquals("[{f0:'f0'}]", r);
}
代码示例来源:origin: apache/juneau
@Test
public void testBeanPropertyProperies() throws Exception {
JsonSerializer s = SimpleJsonSerializer.DEFAULT;
E1 t = new E1();
String r;
r = s.serialize(t);
assertEquals("{x1:{f1:1},x2:{f1:1},x3:[{f1:1}],x4:[{f1:1}],x5:[{f1:1}],x6:[{f1:1}]}", r);
r = s.getSchemaSerializer().serialize(t);
assertTrue(r.indexOf("f2") == -1);
}
代码示例来源:origin: apache/juneau
@Test
public void testSwapOnPrivateField() throws Exception {
JsonSerializer s = SimpleJsonSerializer.DEFAULT;
JsonParser p = JsonParser.DEFAULT;
F1 x = F1.create();
String r = null;
r = s.serialize(x);
assertEquals("{c:'2018-12-12T05:12:00'}", r);
x = p.parse(r, F1.class);
assertObjectEquals("{c:'2018-12-12T05:12:00'}", x);
x = roundTrip(x, F1.class);
}
代码示例来源:origin: apache/juneau
@Test
public void testSubTypeWithGenerics() throws Exception {
JsonSerializer s = JsonSerializer.DEFAULT.builder().addBeanTypes().addRootType().build();
C1 c1 = C3.create();
String r = s.serialize(c1);
assertEquals("{\"_type\":\"C3\",\"f1\":{\"f2\":\"f2\",\"f3\":3}}", r);
}
代码示例来源:origin: apache/juneau
@Test
public void testEscapingSingleQuotes() throws Exception {
JsonSerializer s = SimpleJsonSerializer.DEFAULT;
String r = s.serialize(new ObjectMap().append("f1", "x'x\"x"));
assertEquals("{f1:'x\\'x\"x'}", r);
JsonParser p = JsonParser.DEFAULT;
assertEquals("x'x\"x", p.parse(r, ObjectMap.class).getString("f1"));
}
代码示例来源:origin: apache/juneau
@Test
public void testEscapingDoubleQuotes() throws Exception {
JsonSerializer s = JsonSerializer.DEFAULT;
String r = s.serialize(new ObjectMap().append("f1", "x'x\"x"));
assertEquals("{\"f1\":\"x'x\\\"x\"}", r);
JsonParser p = JsonParser.DEFAULT;
assertEquals("x'x\"x", p.parse(r, ObjectMap.class).getString("f1"));
}
代码示例来源:origin: apache/juneau
@Test
public void testSurrogatesThroughAnnotation() throws Exception {
JsonSerializer s = SimpleJsonSerializer.DEFAULT;
JsonParser p = JsonParser.DEFAULT;
Object r;
E1 x = E1.create();
r = s.serialize(x);
assertEquals("{f2:'f1'}", r);
x = p.parse(r, E1.class);
assertEquals("f1", x.f1);
r = getSerializer().serialize(x);
assertTrue(TestUtils.toString(r).contains("f2"));
x = roundTrip(x, E1.class);
}
代码示例来源:origin: apache/juneau
@Test
public void testBasicBean() throws Exception {
JsonSerializer s = JsonSerializer.create().ssq().trimNullProperties(false).sortProperties().build();
J a = new J();
a.setF1("J");
a.setF2(100);
a.setF3(true);
assertEquals("C1", "{f1:'J',f2:100,f3:true}", s.serialize(a));
}
内容来源于网络,如有侵权,请联系作者删除!