Пример #1
0
 private static boolean encodeObject(Writer writer, Object value, boolean allowJsonResolve)
     throws Exception {
   Converter converter = Converters.getConverter(value.getClass(), String.class);
   if (converter != null) {
     Class clz = converter.getSourceClass();
     String str = (String) converter.convert(value);
     if (clz != null) {
       writer.write(clz.getName());
     } else {
       writer.write(value.getClass().getName());
     }
     writer.write(':');
     writer.write(str);
     return true;
   } else {
     StringWriter sw = new StringWriter();
     IndentingWriter indenting = new IndentingWriter(writer, true, false);
     JSONWriter jsonWriter;
     if (allowJsonResolve) {
       jsonWriter = new JSONWriter(indenting, JSONWriter.ResolvingFallbackHandler);
     } else {
       jsonWriter = new JSONWriter(indenting);
     }
     ;
     jsonWriter.write(value);
     writer.write(sw.toString());
     return true;
   }
 }
Пример #2
0
 private static <S, T> T convertObject(Class<S> sourceClass, S value, Class<T> targetClass)
     throws Exception {
   Converter<S, T> converter = Converters.getConverter(sourceClass, targetClass);
   return converter.convert(targetClass, value);
 }