private boolean append(Object k, Object v, boolean sep) throws IOException { if (k == null) throw new IllegalArgumentException(ERR_NULL_KEY); if (v == null) return false; String key = k.toString(); if (jay.include(key)) { if (sep) w.write(','); w.write('"'); w.write(jay.mapToJson(key)); w.write('"'); w.write(':'); appendValue(v); return true; } return false; }
private void appendValue(Object o) throws IOException { if (o == null) { w.write("null"); } else { o = jay.adaptToJson(o); if (o instanceof Boolean) w.write(o.toString()); else if (o instanceof Number) w.write(o.toString()); else if (o instanceof String) appendEscaped(o.toString()); else if (o instanceof Character) appendEscaped(o.toString()); else if (o instanceof Date) w.write(Long.toString(((Date) o).getTime())); else if (o instanceof Map) append('{', ((Map<?, ?>) o).entrySet(), '}'); else if (o instanceof Iterable) append('[', (Iterable<?>) o, ']'); else if (o.getClass().isArray()) appendArray(o); else if (isSystem(o)) appendEscaped(o.toString()); else appendModel(o); } }