diff --git a/xstream-xmlToObject/.project b/xstream-xmlToObject/.project index 133b92d690..4e1a3f6e92 100644 --- a/xstream-xmlToObject/.project +++ b/xstream-xmlToObject/.project @@ -1,23 +1,14 @@ - xstream-xmlToObject - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - + xstream-xmlToObject + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + + + org.eclipse.jdt.core.javabuilder + + + + org.eclipse.jdt.core.javanature + + \ No newline at end of file diff --git a/xstream-xmlToObject/src/main/java/com/baeldung/initializer/SimpleXstreamInitializer.java b/xstream-xmlToObject/src/main/java/com/baeldung/initializer/SimpleXstreamInitializer.java index 8281678bab..d7dc3f7a81 100644 --- a/xstream-xmlToObject/src/main/java/com/baeldung/initializer/SimpleXstreamInitializer.java +++ b/xstream-xmlToObject/src/main/java/com/baeldung/initializer/SimpleXstreamInitializer.java @@ -4,9 +4,9 @@ import com.thoughtworks.xstream.XStream; public class SimpleXstreamInitializer { - private static XStream xtreamInstance; + private XStream xtreamInstance; - public static XStream getXstreamInstance() { + public XStream getXstreamInstance() { if (xtreamInstance == null) { synchronized (SimpleXstreamInitializer.class) { if (xtreamInstance == null) { diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAnnotationTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAnnotationTest.java index dff671b6a6..10f59e843b 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAnnotationTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAnnotationTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -18,14 +17,16 @@ public class ComplexXmlToObjectAnnotationTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.processAnnotations(Customer.class); } @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-alias-field-complex.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-alias-field-complex.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); Assert.assertNotNull(customer.getContactDetailsList()); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAttributeCollectionTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAttributeCollectionTest.java index 4494cc833d..876a407f76 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAttributeCollectionTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectAttributeCollectionTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -8,8 +7,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import com.baeldung.implicit.collection.pojo.ContactDetails; -import com.baeldung.implicit.collection.pojo.Customer; +import com.baeldung.complex.pojo.ContactDetails; +import com.baeldung.complex.pojo.Customer; import com.baeldung.initializer.SimpleXstreamInitializer; import com.thoughtworks.xstream.XStream; @@ -19,14 +18,16 @@ public class ComplexXmlToObjectAttributeCollectionTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.processAnnotations(Customer.class); } @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-alias-implicit-collection.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-alias-field-complex.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); Assert.assertNotNull(customer.getContactDetailsList()); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectCollectionTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectCollectionTest.java index b72ba44eb5..1656d2f230 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectCollectionTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/ComplexXmlToObjectCollectionTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -18,14 +17,16 @@ public class ComplexXmlToObjectCollectionTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.processAnnotations(Customer.class); } @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-alias-implicit-collection.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-alias-implicit-collection.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); Assert.assertNotNull(customer.getContactDetailsList()); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAliasTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAliasTest.java index 884071542e..cc6d945254 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAliasTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAliasTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -18,14 +17,16 @@ public class XmlToObjectAliasTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.alias("customer" , Customer.class); } @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-alias.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-alias.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAnnotationTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAnnotationTest.java index 09bed7d24f..f2012e2b12 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAnnotationTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectAnnotationTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -18,14 +17,16 @@ public class XmlToObjectAnnotationTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.processAnnotations(Customer.class); } @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-alias-field.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-alias-field.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); Assert.assertNotNull(customer.getFirstName()); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectFieldAliasTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectFieldAliasTest.java index c613a6517c..c4bba86265 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectFieldAliasTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectFieldAliasTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -18,7 +17,8 @@ public class XmlToObjectFieldAliasTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.alias("customer" , Customer.class); xstream.aliasField("fn", Customer.class, "firstName"); } @@ -26,7 +26,8 @@ public class XmlToObjectFieldAliasTest { @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-alias-field.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-alias-field.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); Assert.assertNotNull(customer.getFirstName()); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectIgnoreFieldsTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectIgnoreFieldsTest.java index aa88918402..ca31a22b94 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectIgnoreFieldsTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectIgnoreFieldsTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -18,7 +17,8 @@ public class XmlToObjectIgnoreFieldsTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); xstream.alias("customer" , Customer.class); xstream.ignoreUnknownElements(); } @@ -26,7 +26,8 @@ public class XmlToObjectIgnoreFieldsTest { @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file-ignore-field.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file-ignore-field.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); System.out.println(customer); diff --git a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectTest.java b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectTest.java index cb7fc49b33..e24e54aea4 100644 --- a/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectTest.java +++ b/xstream-xmlToObject/src/test/java/com/baeldung/pojo/test/XmlToObjectTest.java @@ -1,6 +1,5 @@ package com.baeldung.pojo.test; -import java.io.File; import java.io.FileReader; import java.io.IOException; @@ -19,13 +18,15 @@ public class XmlToObjectTest { @Before public void dataSetup() { - xstream = SimpleXstreamInitializer.getXstreamInstance(); + SimpleXstreamInitializer simpleXstreamInitializer = new SimpleXstreamInitializer(); + xstream = simpleXstreamInitializer.getXstreamInstance(); } @Test public void convertXmlToObjectFromFile() { try { - FileReader reader = new FileReader(new File("data-file.xml")); + ClassLoader classLoader = getClass().getClassLoader(); + FileReader reader = new FileReader(classLoader.getResource("data-file.xml").getFile()); Customer customer = (Customer) xstream.fromXML(reader); Assert.assertNotNull(customer); diff --git a/xstream-xmlToObject/src/test/resources/data-file-alias-field-complex.xml b/xstream-xmlToObject/src/test/resources/data-file-alias-field-complex.xml new file mode 100644 index 0000000000..2235aa7044 --- /dev/null +++ b/xstream-xmlToObject/src/test/resources/data-file-alias-field-complex.xml @@ -0,0 +1,15 @@ + + XStream + Java + 1986-02-14 04:14:05.874 UTC + + + 6673543265 + 0124-2460311 + + + 4676543565 + 0120-223312 + + + \ No newline at end of file diff --git a/xstream-xmlToObject/src/test/resources/data-file-alias-field.xml b/xstream-xmlToObject/src/test/resources/data-file-alias-field.xml new file mode 100644 index 0000000000..9bc1d0990a --- /dev/null +++ b/xstream-xmlToObject/src/test/resources/data-file-alias-field.xml @@ -0,0 +1,5 @@ + + XStream + Java + 1986-02-14 03:46:16.381 UTC + \ No newline at end of file diff --git a/xstream-xmlToObject/src/test/resources/data-file-alias-implicit-collection.xml b/xstream-xmlToObject/src/test/resources/data-file-alias-implicit-collection.xml new file mode 100644 index 0000000000..d8731900b9 --- /dev/null +++ b/xstream-xmlToObject/src/test/resources/data-file-alias-implicit-collection.xml @@ -0,0 +1,13 @@ + + XStream + Java + 1986-02-14 04:14:20.541 UTC + + 6673543265 + 0124-2460311 + + + 4676543565 + 0120-223312 + + \ No newline at end of file diff --git a/xstream-xmlToObject/src/test/resources/data-file-alias.xml b/xstream-xmlToObject/src/test/resources/data-file-alias.xml new file mode 100644 index 0000000000..964157f1dd --- /dev/null +++ b/xstream-xmlToObject/src/test/resources/data-file-alias.xml @@ -0,0 +1,5 @@ + + XStream + Java + 1986-02-14 03:46:16.381 UTC + \ No newline at end of file diff --git a/xstream-xmlToObject/src/test/resources/data-file-ignore-field.xml b/xstream-xmlToObject/src/test/resources/data-file-ignore-field.xml new file mode 100644 index 0000000000..865e93d4b4 --- /dev/null +++ b/xstream-xmlToObject/src/test/resources/data-file-ignore-field.xml @@ -0,0 +1,6 @@ + + XStream + Java + 1986-02-14 04:14:20.541 UTC + XStream Java + \ No newline at end of file diff --git a/xstream-xmlToObject/src/test/resources/data-file.xml b/xstream-xmlToObject/src/test/resources/data-file.xml new file mode 100644 index 0000000000..59f2ea1cca --- /dev/null +++ b/xstream-xmlToObject/src/test/resources/data-file.xml @@ -0,0 +1,5 @@ + + XStream + Java + 1986-02-14 03:46:16.381 UTC + \ No newline at end of file