xstream

Generate Java class from XML file, using XStream

坚强是说给别人听的谎言 提交于 2019-12-18 19:41:54
问题 I have many xml files and I would like to use XStream to manage them. Is it possible to generate java classes corresponding to my xml files using XStream? 回答1: XStream is a software to serialize and deserialize a Java Object to and from XML. XStream uses Reflection for this. The class of the objects involved has to exist beforehand. JAXB is a binding framework, which too does serialization and deserialization. JAXB has annotations to do this work. Bundled with the framework come tools to

customising serialisation of java collections using xstream

喜你入骨 提交于 2019-12-18 19:31:53
问题 I have an object that needs to be serialised as XML, which contains the following field: List<String> tags = new List<String>(); XStream serialises it just fine (after some aliases) like this: <tags> <string>tagOne</string> <string>tagTwo</string> <string>tagThree</string> <string>tagFour</string> </tags> That's OK as far as it goes, but I'd like to be able to rename the <string> elements to, say, <tag> . I can't see an obvious way to do that from the alias documentation on the XStream site.

Xstream no-args constructor error

我的梦境 提交于 2019-12-18 19:17:07
问题 I'm getting the following error when it tries to create an instance of 'Transacao' `Error: Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor : Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor ` ---- Debugging information ---- message : Cannot construct br.com.cbmp.ecommerce.resposta.Transacao as it does not have a no-args constructor cause-exception : com.thoughtworks.xstream.converters

XStream - Root as a collection of objects

孤街浪徒 提交于 2019-12-18 03:44:12
问题 I'm consuming an XML payload that looks something like this (for a more comprehensive example, check out : http://api.shopify.com/product.html ). <products type="array"> <product> ... </product> <product> ... </product> </products> Now currently my code does work, but its doing something that appears to be really really "wrong" - namely it associates the "products" with List.class. So the relevant code looks like the following: xstream.alias( "products", List.class ); xstream.alias( "product"

XStream Alias of List root elements

喜夏-厌秋 提交于 2019-12-17 18:43:29
问题 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

parse google geocode with xstream

蹲街弑〆低调 提交于 2019-12-17 17:23:32
问题 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

你知道这高效的12个Java精品库嘛?

微笑、不失礼 提交于 2019-12-16 00:32:52
01. JUnit 第一个要说的当然是JUnit了,JUnit毕竟是Java圈目前最知名及常用的测试框架。JUnit之所以能够成为Java圈中最热门的测试库,是因为对于很多项目而言,单元测试是非常重要的。优点有很多 比如,给开发者提供了简洁的图形界面,可以轻松地写出可重复测试的代码,允许并发同时执行,还允许开发者创建测试套件 (Test Suite) 来查看、检测整体的测试进度及测试期间发生的副作用等。 02. SLF4J SLF4J或Simple Logging Facade for Java,它为不同的框架提供了一个抽象概念,允许开发人员在部署时插入任何框架。它的功能在基于外观的简单日志API,并将客户端API与日志后端分开。 通过向classpath中添加所需的绑定,可以发现其后端。由于客户端API和后端完全解耦,因此它可以集成到任何框架或现有的代码片段。 03. Log4j Log4j是Apache中的一个库,可用作日志工具。 Log4j恰好是其所在应用领域中最可靠的库,可以扩展到支持自定义组件配置。配置语法非常简单,支持XML、YAML 和 JSON。并提供对多个API的支持,最重要的是,它的工作速度相当惊人。 04. Google Guava Google Guava是Java编程的另一个受欢迎的Java核心库 Google

How to unmarshal Map using XStream

给你一囗甜甜゛ 提交于 2019-12-14 02:37:41
问题 I cannot seem to be able to unmarshall a Map properly using XStream. I have the following code: Storage class public class Storage { @XStreamAsAttribute private String basedir; @XStreamAsAttribute private Map<String, Repository> repositories = new LinkedHashMap<String, Repository>(); ... } Repository class public class Repository { @XStreamAsAttribute private String name; @XStreamAsAttribute private String basedir; @XStreamAsAttribute private int policy; @XStreamAsAttribute private int layout

Variable initialization past Xstream

ぃ、小莉子 提交于 2019-12-14 01:28:38
问题 Consider the following declaration as part of SomeClass private Set<String> blah = new HashSet<String>(); Made in a class, which is later XStream xstream = new XStream(new JettisonMappedXmlDriver()); xstream.setMode(XStream.NO_REFERENCES); StringBuilder json = new StringBuilder(xstream.toXML(SomeClass)); rd = (SomeClass) xstream.fromXML(json.toString()); When i @Test assertTrue(rd.getBlah().size() == 0); I get an NPE on rd.getBlah() When I, instead of initializing up front, place

What happens if multiple converters can unmarshal xml?

∥☆過路亽.° 提交于 2019-12-13 21:00:35
问题 Imean that there might be two or more XXXConverter extends ReflectionConverter that might return true here public boolean canConvert(Class aClass) for the same class 回答1: Only one converter will be used for a class. If you register multiple converters with the same priority, then the most recently registered one will be used. Take a look at the source for DefaultConverterLookup . 回答2: I guess they'd both convert it. But I guess the best answer would be to either look it up in the