org.apache.juneau.json.JsonSerializer.serialize()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中org.apache.juneau.json.JsonSerializer.serialize()方法的一些代码示例,展示了JsonSerializer.serialize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonSerializer.serialize()方法的具体详情如下:
包路径:org.apache.juneau.json.JsonSerializer
类名称:JsonSerializer
方法名:serialize

JsonSerializer.serialize介绍

暂无

代码示例

代码示例来源:origin: org.apache.juneau/juneau-marshall

  1. /**
  2. * Convenience method for serializing this ObjectList to the specified Writer using the JsonSerializer.DEFAULT
  3. * serializer.
  4. *
  5. * @param w The writer to send the serialized contents of this object.
  6. * @throws IOException If a problem occurred trying to write to the writer.
  7. * @throws SerializeException If a problem occurred trying to convert the output.
  8. */
  9. public void serializeTo(Writer w) throws IOException, SerializeException {
  10. JsonSerializer.DEFAULT.serialize(this);
  11. }

代码示例来源:origin: apache/juneau

  1. /**
  2. * Convenience method for serializing this map to the specified <code>Writer</code> using the
  3. * {@link JsonSerializer#DEFAULT} serializer.
  4. *
  5. * @param w The writer to serialize this object to.
  6. * @return This object (for method chaining).
  7. * @throws IOException If a problem occurred trying to write to the writer.
  8. * @throws SerializeException If a problem occurred trying to convert the output.
  9. */
  10. public ObjectMap serializeTo(Writer w) throws IOException, SerializeException {
  11. JsonSerializer.DEFAULT.serialize(this);
  12. return this;
  13. }

代码示例来源:origin: apache/juneau

  1. /**
  2. * Convenience method for serializing this ObjectList to the specified Writer using the JsonSerializer.DEFAULT
  3. * serializer.
  4. *
  5. * @param w The writer to send the serialized contents of this object.
  6. * @throws IOException If a problem occurred trying to write to the writer.
  7. * @throws SerializeException If a problem occurred trying to convert the output.
  8. */
  9. public void serializeTo(Writer w) throws IOException, SerializeException {
  10. JsonSerializer.DEFAULT.serialize(this);
  11. }

代码示例来源:origin: cowtowncoder/java-json-performance-benchmarks

  1. @Override
  2. public String _writeAsString(MeasurementPOJO items) throws Exception {
  3. return serializer.serialize(items);
  4. }
  5. }

代码示例来源:origin: apache/juneau

  1. /**
  2. * Convenience method for serializing this ObjectList to the specified Writer using the JsonSerializer.DEFAULT
  3. * serializer.
  4. *
  5. * @param w The writer to send the serialized contents of this object.
  6. * @throws IOException If a problem occurred trying to write to the writer.
  7. * @throws SerializeException If a problem occurred trying to convert the output.
  8. */
  9. public void serializeTo(Writer w) throws IOException, SerializeException {
  10. JsonSerializer.DEFAULT.serialize(this);
  11. }

代码示例来源:origin: org.apache.juneau/juneau-marshall

  1. /**
  2. * Convenience method for serializing this map to the specified <code>Writer</code> using the
  3. * {@link JsonSerializer#DEFAULT} serializer.
  4. *
  5. * @param w The writer to serialize this object to.
  6. * @return This object (for method chaining).
  7. * @throws IOException If a problem occurred trying to write to the writer.
  8. * @throws SerializeException If a problem occurred trying to convert the output.
  9. */
  10. public ObjectMap serializeTo(Writer w) throws IOException, SerializeException {
  11. JsonSerializer.DEFAULT.serialize(this);
  12. return this;
  13. }

代码示例来源:origin: cowtowncoder/java-json-performance-benchmarks

  1. @Override
  2. public int _writeItems(MeasurementPOJO items, Writer out) throws Exception
  3. {
  4. serializer.serialize(items, out);
  5. return items.size();
  6. }

代码示例来源:origin: cowtowncoder/java-json-performance-benchmarks

  1. @Override
  2. public int _writeItems(MeasurementPOJO items, OutputStream out) throws Exception
  3. {
  4. serializer.serialize(items, out);
  5. return items.size();
  6. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testSubclassedList() throws Exception {
  3. JsonSerializer s = JsonSerializer.DEFAULT;
  4. Map<String,Object> o = new HashMap<>();
  5. o.put("c", new C());
  6. assertEquals("{\"c\":[]}", s.serialize(o));
  7. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testBeanPropertyProperiesOnListOfBeans() throws Exception {
  3. JsonSerializer s = SimpleJsonSerializer.DEFAULT;
  4. List<F> l = new LinkedList<>();
  5. F t = new F();
  6. t.x1.add(new F());
  7. l.add(t);
  8. String json = s.serialize(l);
  9. assertEquals("[{x1:[{x2:2}],x2:2}]", json);
  10. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testJson() throws Exception {
  3. JsonSerializer s = JsonSerializer.create().ssq().pojoSwaps(ReaderSwap.Json.class).build();
  4. Reader r;
  5. Map<String,Object> m;
  6. r = new StringReader("{foo:'bar',baz:'quz'}");
  7. m = new HashMap<>();
  8. m.put("X", r);
  9. assertEquals("{X:{foo:'bar',baz:'quz'}}", s.serialize(m));
  10. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testParentClassFilter() throws Exception {
  3. JsonSerializer s = JsonSerializer.create().ssq().beanFilters(C1.class).build();
  4. C1 c1 = new C2();
  5. String r = s.serialize(c1);
  6. assertEquals("{f0:'f0'}", r);
  7. List<C1> l = new LinkedList<>();
  8. l.add(new C2());
  9. r = s.serialize(l);
  10. assertEquals("[{f0:'f0'}]", r);
  11. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testParentClassFilter2() throws Exception {
  3. JsonSerializer s = JsonSerializer.create().ssq().beanFilters(D1.class).build();
  4. D1 d1 = new D2();
  5. String r = s.serialize(d1);
  6. assertEquals("{f0:'f0'}", r);
  7. List<D1> l = new LinkedList<>();
  8. l.add(new D2());
  9. r = s.serialize(l);
  10. assertEquals("[{f0:'f0'}]", r);
  11. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testBeanPropertyProperies() throws Exception {
  3. JsonSerializer s = SimpleJsonSerializer.DEFAULT;
  4. E1 t = new E1();
  5. String r;
  6. r = s.serialize(t);
  7. assertEquals("{x1:{f1:1},x2:{f1:1},x3:[{f1:1}],x4:[{f1:1}],x5:[{f1:1}],x6:[{f1:1}]}", r);
  8. r = s.getSchemaSerializer().serialize(t);
  9. assertTrue(r.indexOf("f2") == -1);
  10. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testSwapOnPrivateField() throws Exception {
  3. JsonSerializer s = SimpleJsonSerializer.DEFAULT;
  4. JsonParser p = JsonParser.DEFAULT;
  5. F1 x = F1.create();
  6. String r = null;
  7. r = s.serialize(x);
  8. assertEquals("{c:'2018-12-12T05:12:00'}", r);
  9. x = p.parse(r, F1.class);
  10. assertObjectEquals("{c:'2018-12-12T05:12:00'}", x);
  11. x = roundTrip(x, F1.class);
  12. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testSubTypeWithGenerics() throws Exception {
  3. JsonSerializer s = JsonSerializer.DEFAULT.builder().addBeanTypes().addRootType().build();
  4. C1 c1 = C3.create();
  5. String r = s.serialize(c1);
  6. assertEquals("{\"_type\":\"C3\",\"f1\":{\"f2\":\"f2\",\"f3\":3}}", r);
  7. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testEscapingSingleQuotes() throws Exception {
  3. JsonSerializer s = SimpleJsonSerializer.DEFAULT;
  4. String r = s.serialize(new ObjectMap().append("f1", "x'x\"x"));
  5. assertEquals("{f1:'x\\'x\"x'}", r);
  6. JsonParser p = JsonParser.DEFAULT;
  7. assertEquals("x'x\"x", p.parse(r, ObjectMap.class).getString("f1"));
  8. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testEscapingDoubleQuotes() throws Exception {
  3. JsonSerializer s = JsonSerializer.DEFAULT;
  4. String r = s.serialize(new ObjectMap().append("f1", "x'x\"x"));
  5. assertEquals("{\"f1\":\"x'x\\\"x\"}", r);
  6. JsonParser p = JsonParser.DEFAULT;
  7. assertEquals("x'x\"x", p.parse(r, ObjectMap.class).getString("f1"));
  8. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testSurrogatesThroughAnnotation() throws Exception {
  3. JsonSerializer s = SimpleJsonSerializer.DEFAULT;
  4. JsonParser p = JsonParser.DEFAULT;
  5. Object r;
  6. E1 x = E1.create();
  7. r = s.serialize(x);
  8. assertEquals("{f2:'f1'}", r);
  9. x = p.parse(r, E1.class);
  10. assertEquals("f1", x.f1);
  11. r = getSerializer().serialize(x);
  12. assertTrue(TestUtils.toString(r).contains("f2"));
  13. x = roundTrip(x, E1.class);
  14. }

代码示例来源:origin: apache/juneau

  1. @Test
  2. public void testBasicBean() throws Exception {
  3. JsonSerializer s = JsonSerializer.create().ssq().trimNullProperties(false).sortProperties().build();
  4. J a = new J();
  5. a.setF1("J");
  6. a.setF2(100);
  7. a.setF3(true);
  8. assertEquals("C1", "{f1:'J',f2:100,f3:true}", s.serialize(a));
  9. }

相关文章