예제 #1
0
파일: UtilIO.java 프로젝트: msc/ofbiz
 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
파일: UtilIO.java 프로젝트: msc/ofbiz
 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);
 }