@Test public void testEncodeToWriter() { StringWriter sWriter = new StringWriter(); JSONCoder.global.encode(new TestBean(), sWriter); String str = sWriter.toString(); log("str=" + str); assertTrue("Encode to writer should succeed", sWriter.toString().contains("intField")); }
public static String encode(EncodeReq req, JSONCoderOption opt) { try { StringBuilder sWriter = null; Appendable writer = req.writer; if (writer == null) { writer = sWriter = new StringBuilder(); } TDNode jsonNode = BeanCoder.get().encode(req.object, new BeanCoderContext(opt), req.type); TDJSONWriter.get().write(writer, jsonNode, opt.getJsonOption()); return sWriter == null ? null : sWriter.toString(); } catch (Exception e) { throw new BeanCoderException(e); } }
JSONCoder { public static String encode(EncodeReq req, JSONCoderOption opt) { try { StringBuilder sWriter = null; Appendable writer = req.writer; if (writer == null) { writer = sWriter = new StringBuilder(); } TDNode jsonNode = BeanCoder.get().encode(req.object, new BeanCoderContext(opt), req.type); TDJSONWriter.get().write(writer, jsonNode, opt.getJsonOption()); return sWriter == null ? null : sWriter.toString(); } catch (Exception e) { throw new BeanCoderException(e); } } }
JSONCoder { public static String encode(EncodeReq req, JSONCoderOption opt) { try { StringBuilder sWriter = null; Appendable writer = req.writer; if (writer == null) { writer = sWriter = new StringBuilder(); } TDNode jsonNode = BeanCoder.get().encode(req.object, new BeanCoderContext(opt), req.type); TDJSONWriter.get().write(writer, jsonNode, opt.getJsonOption()); return sWriter == null ? null : sWriter.toString(); } catch (Exception e) { throw new BeanCoderException(e); } } JSONCoder(JSONCoderOption option); }
JSONCoder { public static String encode(EncodeReq req, JSONCoderOption opt) { try { StringBuilder sWriter = null; Appendable writer = req.writer; if (writer == null) { writer = sWriter = new StringBuilder(); } TDNode jsonNode = BeanCoder.get().encode(req.object, new BeanCoderContext(opt), req.type); TDJSONWriter.get().write(writer, jsonNode, opt.getJsonOption()); return sWriter == null ? null : sWriter.toString(); } catch (Exception e) { throw new BeanCoderException(e); } } JSONCoder(JSONCoderOption option); @SuppressWarnings("unchecked") static T decode(DecodeReq<T> req, JSONCoderOption opt); @SuppressWarnings({"unchecked", "WeakerAccess"}) static T decode(String jsonStr, Class<T> type, JSONCoderOption opt); @SuppressWarnings("unchecked") static T decode(Reader reader, Class<T> type, JSONCoderOption opt); static T decode(CharSource source, Class<T> type, JSONCoderOption opt); @SuppressWarnings("unchecked") static T decode(TDNode treeDocNode, Class<T> type, JSONCoderOption opt); T decode(DecodeReq<T> req); T decodeTo(String str, T target); T decode(String str, Class<T> type); @SuppressWarnings("unchecked") T decode(Reader reader, Class<T> type); T decode(CharSource source, Class<T> type); @SuppressWarnings("unchecked") T decode(TDNode treeDocNode, Class<T> type); static String encode(EncodeReq req, JSONCoderOption opt); static String encode(Object obj, JSONCoderOption opt); static void encode(Object obj, Writer writer, JSONCoderOption opt); String encode(EncodeReq req); String encode(Object obj); void encode(Object obj, Writer writer); }
JSONCoder { public static String encode(EncodeReq req, JSONCoderOption opt) { try { StringBuilder sWriter = null; Appendable writer = req.writer; if (writer == null) { writer = sWriter = new StringBuilder(); } TDNode jsonNode = BeanCoder.get().encode(req.object, new BeanCoderContext(opt), req.type); TDJSONWriter.get().write(writer, jsonNode, opt.getJsonOption()); return sWriter == null ? null : sWriter.toString(); } catch (Exception e) { throw new BeanCoderException(e); } } JSONCoder(JSONCoderOption option); @SuppressWarnings("unchecked") static T decode(DecodeReq<T> req, JSONCoderOption opt); @SuppressWarnings({"unchecked", "WeakerAccess"}) static T decode(String jsonStr, Class<T> type, JSONCoderOption opt); @SuppressWarnings("unchecked") static T decode(Reader reader, Class<T> type, JSONCoderOption opt); static T decode(CharSource source, Class<T> type, JSONCoderOption opt); @SuppressWarnings("unchecked") static T decode(TDNode treeDocNode, Class<T> type, JSONCoderOption opt); T decode(DecodeReq<T> req); T decodeTo(String str, T target); T decode(String str, Class<T> type); @SuppressWarnings("unchecked") T decode(Reader reader, Class<T> type); T decode(CharSource source, Class<T> type); @SuppressWarnings("unchecked") T decode(TDNode treeDocNode, Class<T> type); static String encode(EncodeReq req, JSONCoderOption opt); static String encode(Object obj, JSONCoderOption opt); static void encode(Object obj, Writer writer, JSONCoderOption opt); String encode(EncodeReq req); String encode(Object obj); void encode(Object obj, Writer writer);  }