- } else if (line.startsWith("REF ")) { // REF: create/link self
- String ref = line.substring(4).split("@")[1];
- link = map.containsKey(ref);
- if (link) {
- me = map.get(ref);
- } else {
- me = SerialUtils.createObject(line.substring(4).split("@")[0]);
- map.put(ref, me);
+ }
+
+ // Custom objects
+ if (CustomSerializer.isCustom(in)) {
+ // not a field value but a direct value
+ me = SerialUtils.decode(in);
+ return false;
+ }
+
+ // REF: (object)
+ if (in.startsWith("REF ")) { // REF: create/link self
+ // here, line is REF type@999:xxx
+ // xxx is optional
+
+ NextableInputStream stream = new NextableInputStream(in,
+ new NextableInputStreamStep(':'));
+ try {
+ stream.next();
+
+ stream.skip("REF ".length());
+ String header = IOUtils.readSmallStream(stream);
+
+ String[] tab = header.split("@");
+ if (tab.length != 2) {
+ throw new IOException("Bad import header line: " + header);
+ }
+ String type = tab[0];
+ String ref = tab[1];
+
+ stream.nextAll();
+
+ link = map.containsKey(ref);
+ if (link) {
+ me = map.get(ref);
+ stream.end();
+ } else {
+ if (stream.eof()) {
+ // construct
+ me = SerialUtils.createObject(type);
+ } else {
+ // direct value
+ me = SerialUtils.decode(stream);
+ }
+ map.put(ref, me);
+ }
+ } finally {
+ stream.close(false);