Details
-
Type: Bug
-
Status: Closed
-
Priority: Minor
-
Resolution: Not A Bug
-
Affects Version/s: 1.4.4
-
Fix Version/s: None
-
Component/s: Converters
-
Labels:None
-
JDK version and platform:Sun 1.7.0_40 for Windows 64-Bit
Description
Great product, but you already know that...
Note the 1 underscore changed to 2 underscores. I tried to use the alias to fix it but it had no effect.
class:
public class Gallery {
private String title;
private String description;
private String file_root;
private String thumb_src;
private ArrayList<GImage> images = new ArrayList();
public void Gallery () {
}
code to generate xml:
public void saveGalleryToFile(File file) {
XStream xstream = new XStream();
xstream.alias("gallery", Gallery.class);
xstream.alias("image", GImage.class);
xstream.aliasField("file_root", Gallery.class, "file__root");
xstream.aliasField("thumb_src", Gallery.class, "thumb__src");
xstream.aliasField("image_src", GImage.class, "image__src");
xstream.aliasField("thumb_src", GImage.class, "thumb__src");
xstream.omitField(GImage.class, "remove");
// Convert ObservableList to a normal ArrayList
ArrayList<Gallery> galleryList = new ArrayList<>(galleryData);
String xml = xstream.toXML(galleryList);
Sample output:
<list>
<gallery>
<title></title>
<description></description>
<file_root>C:\Simple</file_root>
<thumb_src>\thumbs\IMG_1849.jpg</thumb_src>
<images>
<image>
<title>Title #0</title>
<description>Description #0</description>
<image_src>\images\IMG_1848.jpg</image_src>
<thumb_src>\thumbs\IMG_1848.jpg</thumb_src>
</image>
http://xstream.codehaus.org/faq.html#XML_double_underscores