xstream

XStream: convert collection with attributes

梦想的初衷 提交于 2019-12-08 03:22:07
问题 The XML I'm trying to convert looks like: <numberOfEmployees year="2013">499.0</numberOfEmployees> According to the XSD, there can be multiple of these tags, so it's a collection. The generated code looks like: protected List<NumberOfPersonnel> numberOfEmployees; When I use @XStreamImplicit , it drops the value, so I need a converter. But combining @XStreamImplicit with @XStreamConverter doesn't seem to work. So how do I do this? I've tried messing about with my own custom converter that

How to map an Hashmap to key-value-attributes in XML using xstream

不打扰是莪最后的温柔 提交于 2019-12-07 12:22:37
问题 I have the following entity: @XStreamAlias("entity") public class MapTestEntity { @XStreamAsAttribute public Map<String, String> myMap = new HashMap<>(); @XStreamAsAttribute public String myText; } I use it with xstream like: MapTestEntity e = new MapTestEntity(); e.myText = "Foo"; e.myMap.put("firstname", "homer"); e.myMap.put("lastname", "simpson"); XStream xstream = new XStream(new PureJavaReflectionProvider()); xstream.processAnnotations(MapTestEntity.class); System.out.println(xstream

XStream: Collapsing XML hierarchy as I parse

为君一笑 提交于 2019-12-07 03:45:00
问题 I have an XML document (generated by Adobe XFA forms), that contains data like the following: <Position> <PositionBorder> <Title/> <StartDate/> <EndDate/> </PositionBorder> </Position> Since this file is defined elsewhere, I am not at liberty to change the format of the XML that I get. In my Java code, I create a Position class that contains the Title, Start and End Dates. My problem is, when I use XStream to parse the file, it wants a PositionBorder class to hold the title and dates. I want

XStream parse JSON with no root node

早过忘川 提交于 2019-12-07 03:32:15
问题 I am currently deserializing JSON using XStream, and it has been working great. However, when I have JSON string like the following { key1: { an_object: { something: 'foobar' } }, key2: { another_object: { data: 'hi' } } most notably it doesn't have a root node, I'm not sure how to parse it. Basically, I want the opposite of DROP_ROOT_NODE for the deserialization. 回答1: The short answer is "you can't". XStream needs to know what class to instantiate, it gets that knowledge from JSON (or XML)

你的第一杯Web 2.0 —— 快速浏览jQuery、Spring MVC和XStream/J...

时光毁灭记忆、已成空白 提交于 2019-12-06 19:01:58
不再有页面刷新:使用jQuery 相关厂商内容 免费迷你书下载:Flex入门指南——PHP开发者 Flash Builder 4 Beta和FlexUnit下的测试驱动开发 下载Flex 4 SDK,构建超级棒的Flex应用 使用Pixel Bender Toolkit制作特效——创建vintage tone过滤器(Part 2) 在Flash Builder4 beta中使用网络监测器跟踪网络流量 相关赞助商 汇集最新RIA技术相关资源,提供Flash开发平台相关工具高速下载,免费获得Adobe软件的产品序列号。 在我参与创建的一些Web网站应用中,一直存在有对用户理所当然的抱歉:“哦,对不起,我不得不让你经受一些不必要的页面刷新。”哈,这就是我在今年年初听说jQuery后,我的脑子里一下闪过的念头。 jQuery是个强大而非侵入式的JavaScript库,但它的名字起得很差劲。它的简洁而高可读性的语法再次激发了我编写JavaScript代码的兴趣。它的非侵入性能让它只需要对既有代码做小小的修改,就能很容易为web应用添加一些丰富的功能——比如后台表单提交。当你工作在一个很大的代码库,或者扩展性的重构无法取得成效时,非侵入的特性显得尤其重要。我的老板不会给我四周的时间推倒重来,为一个已经存在的网站添加一些视觉效果。但我也许可以有四个小时的时间,而这对jQuery来说足够了。

XStream使用中的几个问题

佐手、 提交于 2019-12-06 16:42:34
一、背景 写接口过程中,xml和json是最基本的两种返回类型。 fastjson可以很方便的解决json和Pojo之间的转换,我们就希望再找一个实现xml和Pojo之间转换的库,这样就能将实例化的对象,根据接口请求返回数据类型,直接转换成相应格式的返回值。一方面提高开发速度,另一方面后期方便维护。 最终决定使用 thoughtworks的XStream库 。微信开发中用了一段时间,因为微信涉及的xml格式比较简单,很多问题没有出现,现在开发API接口过程中,一些基本问题就出现了。 二、问题 1、 Annotation无效 开始为了将Pojo对应属性名改成想要的,都是使用alias: xstream.alias("item", Item.class); 这样使用太麻烦,最好使用注解 2、 这里是列表文本文本内容无法增加<![CDATA[这是文本]]> 从惯例来看,这里最好使用CDATA包裹 3、 如果Pojo属性包含下划线,生成的xml变成双下划线 Pojo属性,不包含下划线,就不会有这个问题。如果是新项目建议不要使用下划线,驼峰式还是首选的。 三、解决方法 官方文档就有,只是不知道: http://x-stream.github.io/annotations-tutorial.html XStream stream = new XStream(); xstream

Intercepting Xstream while parsing XML

99封情书 提交于 2019-12-06 14:17:21
Suppose I have a simple Java class like this: public class User { String firstName; String lastName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } } Now, suppose I want to parse the following XML: <user> <firstName>Homer</firstName> <lastName>Simpson</lastName> </user> I can do this with no problems in XStream like so: User homer = (User) xstream.fromXML(xml); Ok, all good so far, but here's my

XStream won't call readObject()

你。 提交于 2019-12-06 13:03:29
I have code that is modeled as such: class A { private transient Foo foo = new Foo(); private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); foo = new Foo(); } } class B extends A {} I added readObject() to A so that during deserialization, the transient foo will be initialized. However, I stuck breakpoints in my code and could see that XStream is not calling readObject() at all. I also tried sticking readObject() in class B that calls an initFoo() function in A, and that didn't work either. The FAQ on the website does not seem to

Polymorphism in XStream serialization and deserialization

给你一囗甜甜゛ 提交于 2019-12-06 06:33:08
问题 I have these classes: @XStreamAlias("person") public class PersonConfig { private AnimalConfig animalConfig; } public interface AnimalConfig {} @XStreamAlias("dog"); public class DogConfig extend AnimalConfig {} @XStreamAlias("cat"); public class CatConfig extend AnimalConfig {} And I would like to be able to deserialize this xml with the classes above: <person> <dog/> <person> As well as deserialize this xml too, with the same classes: <person> <cat/> <person> So that in both cases, the

Problem with deserialization of String sent over wire with XStream

感情迁移 提交于 2019-12-06 00:34:07
I am trying to create a simple webservice which takes a String as input and returns string as output. I am using Ecelipse Helios and Axis 2.15. I am writing simple WSDL for the same. I am generating the stubs using code generator. New ->code generator -> java class from wsdl-> give WSDL and generates the java skeletons. And in the skelton I am just print the value what is coming as parameter. and returning the same value. I have written client code to invoke the method of the webservice. which takes a String. but when I am trying to invoke the method I am getting following exception and it's