public static void toJson(Object obj, JsonWriter writer) throws IOException { if (obj == null) { writer.writeNull(); return; } Class<?> clazz = obj.getClass(); Serializer serializer = getSerializer(clazz); serializer.convertTo(writer, obj); }