X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2FSerialUtils.java;h=706d579970f9456fd430d4ae2020185aa8c7ed24;hb=a359464fcf59af8abc6f69ae0e88e42adc6018df;hp=61bca4f6d1a9b0e238c44b72c4589327d53d09e8;hpb=72648e757f648cd152bc00dfb83f895260f037a0;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/SerialUtils.java b/src/be/nikiroo/utils/serial/SerialUtils.java index 61bca4f..706d579 100644 --- a/src/be/nikiroo/utils/serial/SerialUtils.java +++ b/src/be/nikiroo/utils/serial/SerialUtils.java @@ -66,8 +66,8 @@ public class SerialUtils { if (!SerialUtils.encode(builder, item)) { try { // use ZIP: if not - builder.append(new Exporter().append(item) - .toString(true)); + new Exporter().append(item).appendTo(builder, + true, false); } catch (NotSerializableException e) { throw new UnknownFormatConversionException(e .getMessage()); @@ -173,7 +173,6 @@ public class SerialUtils { throws ClassNotFoundException, NoSuchMethodException { String desc = null; - try { Class clazz = getClass(type); String className = clazz.getName(); @@ -183,11 +182,11 @@ public class SerialUtils { if (className.contains("$")) { for (String parentName = className.substring(0, className.lastIndexOf('$'));; parentName = parentName - .substring(0, parentName.lastIndexOf('$'))) { + .substring(0, parentName.lastIndexOf('$'))) { Object parent = createObject(parentName); args.add(parent); classes.add(parent.getClass()); - + if (!parentName.contains("$")) { break; } @@ -199,7 +198,7 @@ public class SerialUtils { String end = ""; for (Class parent = clazz; parent != null && !parent.equals(Object.class); parent = parent - .getSuperclass()) { + .getSuperclass()) { if (!desc.isEmpty()) { desc += " [:"; end += "]"; @@ -209,8 +208,18 @@ public class SerialUtils { desc += end; // - ctor = clazz.getDeclaredConstructor( - classes.toArray(new Class[] {})); + try { + ctor = clazz.getDeclaredConstructor(classes + .toArray(new Class[] {})); + } catch (NoSuchMethodException nsme) { + // TODO: it seems e do not always need a parameter for each + // level, so we currently try "ALL" levels or "FIRST" level + // only -> we should check the actual rule and use it + ctor = clazz.getDeclaredConstructor(classes.get(0)); + Object firstParent = args.get(0); + args.clear(); + args.add(firstParent); + } desc = null; } else { ctor = clazz.getDeclaredConstructor(); @@ -222,8 +231,8 @@ public class SerialUtils { throw e; } catch (NoSuchMethodException e) { if (desc != null) { - throw new NoSuchMethodException( - "Empty constructor not found: " + desc); + throw new NoSuchMethodException("Empty constructor not found: " + + desc); } throw e; } catch (Exception e) { @@ -326,7 +335,13 @@ public class SerialUtils { } /** - * Encode the object into the given builder if possible (if supported). + * Encode the object into the given builder if possible and if supported. + *

+ * A supported object in this context means an object we can directly + * encode, like an Integer or a String. Custom objects and arrays are also + * considered supported, but compound objects are not supported here. + *

+ * For compound objects, you should use {@link Exporter}. * * @param builder * the builder to append to @@ -377,7 +392,13 @@ public class SerialUtils { } /** - * Decode the data into an equivalent source object. + * Decode the data into an equivalent supported source object. + *

+ * A supported object in this context means an object we can directly + * encode, like an Integer or a String. Custom objects and arrays are also + * considered supported, but compound objects are not supported here. + *

+ * For compound objects, you should use {@link Importer}. * * @param encodedValue * the encoded data, cannot be NULL