Making nullOut behavior opt-in, so limiting to AbstractItem and View (and in particular not Jenkins).

This commit is contained in:
Jesse Glick committed 2017-12-14 13:16:42 -05:00
1 parent 3aa523969d
commit ddb9ad68b4
5 files changed
+60 -18

No files matched your search

+16 -1
View File
@@ -159,10 +159,25 @@ public final class XmlFile {
* if the XML representation is completely new.
*/
public Object unmarshal( Object o ) throws IOException {
return unmarshal(o, false);
}
/**
* Variant of {@link #unmarshal(Object)} applying {@link XStream2#unmarshal(HierarchicalStreamReader, Object, DataHolder, boolean)}.
* @since FIXME
*/
public Object unmarshalNullingOut(Object o) throws IOException {
return unmarshal(o, true);
}
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
return xs.unmarshal(DEFAULT_DRIVER.createReader(in), o);
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);
}