/** * Deserialize an object from a hierarchical data structure (such as XML). * * @throws XStreamException if the object cannot be deserialized */ public Object unmarshal(HierarchicalStreamReader reader) { return unmarshal(reader, null, null); }
/** * Deserialize an object from a hierarchical data structure (such as XML), populating the * fields of the given root object instead of instantiating a new one. Note, that this is a * special use case! With the ReflectionConverter XStream will write directly into the raw * memory area of the existing object. Use with care! * * @throws XStreamException if the object cannot be deserialized */ public Object unmarshal(HierarchicalStreamReader reader, Object root) { return unmarshal(reader, root, null); }
/** * Unmarshals this DOM into an object via the given XStream. */ public <T> T unmarshal(XStream xs) { return (T)xs.unmarshal(newReader()); }
public <T> T unmarshal(XStream xs, T root) { return (T)xs.unmarshal(newReader(),root); }
/** * Unmarshals the given graph to the given XStream HierarchicalStreamWriter. * Converts exceptions using {@link #convertXStreamException}. */ private Object doUnmarshal(HierarchicalStreamReader streamReader, @Nullable DataHolder dataHolder) { try { return getXStream().unmarshal(streamReader, null, dataHolder); } catch (Exception ex) { throw convertXStreamException(ex, false); } }
private Object unmarshal(Object o, boolean nullOut) throws IOException { try (InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()))) { // TODO: expose XStream the driver from XStream if (nullOut) { return ((XStream2) xs).unmarshal(DEFAULT_DRIVER.createReader(in), o, null, true); } else { return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o); } } catch (RuntimeException | Error e) { throw new IOException("Unable to read "+file,e); } }
/** * Deserialize an object from an XML InputStream. * * @throws XStreamException if the object cannot be deserialized */ public Object fromXML(InputStream input) { return unmarshal(hierarchicalStreamDriver.createReader(input), null); }
/** * Deserialize an object from an XML InputStream, populating the fields of the given root * object instead of instantiating a new one. Note, that this is a special use case! With * the ReflectionConverter XStream will write directly into the raw memory area of the * existing object. Use with care! * * @throws XStreamException if the object cannot be deserialized */ public Object fromXML(InputStream input, Object root) { return unmarshal(hierarchicalStreamDriver.createReader(input), root); }
/** * Deserialize an object from an XML Reader, populating the fields of the given root object * instead of instantiating a new one. Note, that this is a special use case! With the * ReflectionConverter XStream will write directly into the raw memory area of the existing * object. Use with care! * * @throws XStreamException if the object cannot be deserialized */ public Object fromXML(Reader xml, Object root) { return unmarshal(hierarchicalStreamDriver.createReader(xml), root); }
/** * Deserialize an object from an XML Reader. * * @throws XStreamException if the object cannot be deserialized */ public Object fromXML(Reader reader) { return unmarshal(hierarchicalStreamDriver.createReader(reader), null); }
/** * Deserialize an object from a URL, populating the fields of the given root * object instead of instantiating a new one. Note, that this is a special use case! With * the ReflectionConverter XStream will write directly into the raw memory area of the * existing object. Use with care! * * Depending on the parser implementation, some might take the file path as SystemId to * resolve additional references. * * @throws XStreamException if the object cannot be deserialized * @since 1.4 */ public Object fromXML(URL url, Object root) { return unmarshal(hierarchicalStreamDriver.createReader(url), root); }
public Object readFromStream() throws EOFException { if (!reader.hasMoreChildren()) { throw new EOFException(); } reader.moveDown(); final Object result = unmarshal(reader, dataHolder); reader.moveUp(); return result; }
/** * Deserialize an object from a file, populating the fields of the given root * object instead of instantiating a new one. Note, that this is a special use case! With * the ReflectionConverter XStream will write directly into the raw memory area of the * existing object. Use with care! * * Depending on the parser implementation, some might take the file path as SystemId to * resolve additional references. * * @throws XStreamException if the object cannot be deserialized * @since 1.4 */ public Object fromXML(File file, Object root) { HierarchicalStreamReader reader = hierarchicalStreamDriver.createReader(file); try { return unmarshal(reader, root); } finally { reader.close(); } }
@SuppressWarnings({"unchecked"}) @Override public Object doDeserialize(SerializedObject serializedObject, XStream xStream) { if ("org.dom4j.Document".equals(serializedObject.getContentType().getName())) { return xStream.unmarshal(new Dom4JReader((org.dom4j.Document) serializedObject.getData())); } if ("nu.xom.Document".equals(serializedObject.getContentType().getName())) { return xStream.unmarshal(new XomReader((nu.xom.Document) serializedObject.getData())); } InputStream serializedData = convert(serializedObject.getData(), serializedObject.getContentType(), InputStream.class); return xStream.fromXML(new InputStreamReader(serializedData, getCharset())); }
/** * Deserialize an object from a hierarchical data structure (such as XML). * * @throws XStreamException if the object cannot be deserialized */ public <T> T unmarshal(final HierarchicalStreamReader reader) { return unmarshal(reader, null, null); }
/** * Unmarshals this DOM into an object via the given XStream. */ public <T> T unmarshal(XStream xs) { return (T)xs.unmarshal(newReader()); }
/** * Parse an element with a lot of simple children. * * @since 1.4.9 */ @Benchmark public void parseManyChildren() { final Object o = xstream.unmarshal(driver.createReader(new ByteArrayInputStream(data))); dataFactory.checkData(o); } }
/** * Parse an element with a big text as value. * * @since 1.4.9 */ @Benchmark public void parseBigText() { final Object o = xstream.unmarshal(driver.createReader(new ByteArrayInputStream(data))); dataFactory.checkData(o); }
@Override public Object readFromStream() throws EOFException { if (!reader.hasMoreChildren()) { throw new EOFException(); } reader.moveDown(); final Object result = unmarshal(reader, dataHolder); reader.moveUp(); return result; }