xstream

How do I encode UTF-8 using the XStream framework?

孤街浪徒 提交于 2019-11-28 18:25:31
Per XStream's FAQ its default parser does not preserve UTF-8 document encoding, and one must provide their own encoder. How does one do this? Thanks! Create a Writer with UTF-8 encoding. Pass the Writer as an argument to XStream's toXML method. XStream xstream = new xStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); Writer writer = new OutputStreamWriter(outputStream, "UTF-8"); xStream.toXML(object, writer); String xml = outputStream.toString("UTF-8"); You may also use that Writer to include the XML Declaration. writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?

xstream CannotResolveClassException

梦想与她 提交于 2019-11-28 13:22:31
I'm trying to use xstream 1.4.2 to convert xml to object. It does work perfectly fine for me until I put the object's class file in a separate package than where the main code runs. Then I get a CannotResolveClassException. I've tried using the setClassLoader method as recommended by others but that doesn't help. Exception in thread "main" com.thoughtworks.xstream.mapper.CannotResolveClassException: result at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:56) at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:30) at com.thoughtworks

Android Gradle Plugin 3.0.0: Multiple dex files define Lorg/xmlpull/mxp1/MXParser with XStream

拜拜、爱过 提交于 2019-11-28 09:08:44
问题 Included projects that bring their own xmlpullparser always needed some extra care in Android Studio since Android brings its own xmlpullparser. E.g. the popular XML mapper XStream required this exclude (1) (2) : compile('com.thoughtworks.xstream:xstream:1.4.7') { exclude group: 'xmlpull', module: 'xmlpull' //exclude xmlpull to avoid `Multiple dex files define`-error } Somewhere else I also have seen: compile('com.thoughtworks.xstream:xstream:1.4.7') { exclude group: 'xmlpull' exclude group:

XStream Alias of List root elements

拜拜、爱过 提交于 2019-11-28 08:33:34
I want to be able to alias the root list element depending upon what type of objects are contained in the list. For example, this is my current output: <list> <coin>Gold</coin> <coin>Silver</coin> <coin>Bronze</coin> </list> And this is what I want it to look like: <coins> <coin>Gold</coin> <coin>Silver</coin> <coin>Bronze</coin> </coins> I can do this at a global level by saying all lists should be aliased to coins, but I have a lot of different lists and this won't work. Any ideas on how to do this? Seems like it should be simple, but of course, it isn't. EDIT: I should specify, I am trying

How to convert List of Object to XML doc using XStream

自闭症网瘾萝莉.ら 提交于 2019-11-28 08:31:59
How to convert List of Object to XML doc using XStream ? and how to deserialize it back ? This is my xml <?xml version="1.0" encoding="UTF-8"?> <persons> <person> <fullname>Guilherme</fullname> <age>10</age> <address>address,address,address,address,</address> </person> <person> <fullname>Guilherme</fullname> <age>10</age> <address>address,address,address,address,</address> </person> </persons> Person bean contains 3 fields how to convert back it to Bean List using custom converters ? dogbane You don't necessarily need a CustomConverter. You need a class to hold your list: public class

XStream : node with attributes and text node?

a 夏天 提交于 2019-11-28 07:32:21
I would like to serialize an object to an XML of this form with XStream. <node att="value">text</node> The value of the node ( text ) is a field on the serialized object, as well as the att attribute. Is this possible without writing a converter for this object? Thanks! write a convertor, it should be something similar to the code snippet class FieldDtoConvertor implements Converter { @SuppressWarnings("unchecked") public boolean canConvert(final Class clazz) { return clazz.equals(FieldDto.class); } public void marshal(final Object value, final HierarchicalStreamWriter writer, final

Modern alternative to Java XStream library?

久未见 提交于 2019-11-28 06:57:26
I used XStream many years ago, but I see that the libraries is not updated since 2008 ( latest news ). Is there now a more modern and up to dates Java XML serialization library? haylem In order of preference, relevancy and activity: JAXB Visit the JAXB project's site to check out the tutorial and guide . Have also a look at the original JAXB architecture whitepaper . The JAXB projet listed above is the reference implementation of the API, and is packaged in by the GlassFish Application Server. EclipseLink 's MOXy Visit the EclipseLink project's site and read this introductory article to

parse google geocode with xstream

泪湿孤枕 提交于 2019-11-28 02:14:53
I'm using Java and XStream to parse a google geocode request over http. My idea is to have an Address class with all the geocode attr's (ie. lat/long, city, provice/state etc) but I'm having problems parsing the xml with xstream. The google response is similar to this: <?xml version="1.0" encoding="UTF-8" ?> <kml xmlns="http://earth.google.com/kml/2.0"><Response> <name>98 St. Patrick St, Toronto</name> <Status> <code>200</code> <request>geocode</request> </Status> <Placemark id="p1"> <address>98 St Patrick St, Toronto, ON, Canada</address> <AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc

Format XML generated by Xstream

我是研究僧i 提交于 2019-11-28 01:58:49
I want to format the output XML generated by Xstream, to make it more readable. Currently, a newline is added after each element but I would like newline to be added after every attribute. Is there a way to do this? Pretty Print Writer is used by default to format the output of the xml but this doesn't suffice for me. I want newline to be added after every XStream includes a PrettyPrintWriter After building your XStream... XStream xstream = //...whatever Instead of: // p is my object needing xml serialization xstream.toXML(p) Use something like this to make it pretty: BufferedOutputStream

XStream别名;元素转属性;去除集合属性(剥皮);忽略不需要元素

▼魔方 西西 提交于 2019-11-27 23:42:44
city package xstream; public class City { private String name; private String description; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public City(String name, String description) { this.name = name; this.description = description; } } province package xstream; import java.util.ArrayList; import java.util.List; public class Province { private String name; private List<City> cities = new ArrayList<City>();