xstream

Define namespaces tags so that generated XML have those tags?

假装没事ソ 提交于 2019-12-11 07:00:02
问题 I have two classes People.java and PeopleMain.java People.java package com.test; public class People { private String name; private String age; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } } PeopleMain.java package com.test; import com.thoughtworks.xstream.XStream; public class PeopleMain { public static void main(String args[]){ People p= new People();

Using Xstream for dynamic creating object (Java)

僤鯓⒐⒋嵵緔 提交于 2019-12-11 05:19:28
问题 I am using Xstream to parse XML file. the ideal format of the XML file is: <Line> <P Name="Src">5</P> <P Name="Dst">4</P> </Line> however, sometimes, the infomation would be: <Line> <P Name="Src">2</P> <P Name="Points">[3, 0]</P> <Branch> <P Name="Points">[0, 8]</P> <P Name="Dst">5</P> </Branch> <Branch> <P Name="Dst">3</P> </Branch> </Line> The Points part could be ignored. actually the above information means a fork line: <Line> <P Name="Src">2</P> <P Name="Dst">5</P> </Line> <Line> <P Name

Problem unmarshalling an attribute with name “class” with Xstream

自古美人都是妖i 提交于 2019-12-11 04:57:11
问题 I have a node with an attribute named class . The input XML is : <Job class="com.test.jobImplementation"> <Priority>1</Priority> ...... </Job> The Java class which represents the XML is annotated with Xstream annotations is as follows: @XStreamAlias("Job") public static class Job { @XStreamAsAttribute @XStreamAlias("class") private String implementationClass; @XStreamAlias("Priority") private Integer priority } When I try to deserialize the XML, xstream fails returning an error unrelated to

XStream serializing collections

烂漫一生 提交于 2019-12-11 04:16:50
问题 I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that are stored in the collection (primarily their IDs, and not the remaining contents of each element). Anyone have an idea of how I might go about this? Thanks 回答1: You can specify that all the collection element fields except for ID should not be serialized by either: Declaring them transient

XStream apostrophe Issue in converting Java Object to XML

落花浮王杯 提交于 2019-12-11 04:07:19
问题 I am using com.thoughtworks.xstream.XStream to Generate xml String. I parse Object to xstream. toXML method and I get the xml output according to the way I need. <myxml> <test type="test" name="test"> <question id="Name" answer="Micheal"/> <question id="Address" answer="Home"> <details name="First Address"> <detailanswer>friend&apos;s House</detailanswer> </details> </basequestion> </test> </myxml> XStream xstream = new XStream(); xstream.alias("myxml", MyXml.class); xstream.alias("test",

How to configure XStream to map to different classes depending on XML attributes?

余生长醉 提交于 2019-12-11 03:29:41
问题 I have the following Java object hierarchy: public interface Function { public void calculate(long t); } public class ConstantFunction implements Function { private double constant; @Override public void calculate(long t) { // ... } } public class LinearFunction implements Function { private double slope; private double yIntercept; @Override public void calculate(long t) { // ... } } Users can create ConstantFunction and LinearFunction instances by defining them inside XML like so: <myapp>

XStream arrayList to and from XML

夙愿已清 提交于 2019-12-11 03:28:00
问题 I do not know where the problem is at the moment. First time using xml, and I got some problems with putting ArrayList in xml file and taking it from it. I was found this and I tried to do it same way: How to convert List of Object to XML doc using XStream but unfortunately I failed. Here what I have so far: Class that holds ArrayList: public class ElbowList{ private ArrayList<Elbow> elbows = new ArrayList<>(); public ElbowList(){ elbows = new ArrayList<Elbow>(); } public void setElbows

Xstream to map “choice” elements of XML

廉价感情. 提交于 2019-12-11 02:35:13
问题 I need to map an XML, constrained by an XSD to Java object using XStream. The XSD has 4 complex type elements, which are "choice" elements, that is either one of those 4 can be present in the XML under a root tag. I have been looking at XStream but it seems to me that, to map such an XML, I would require 8 classes. How? here it is... Say for example my root element is VEHICLE and each of the complex types in the XML are a) CAR b) BIKE c) TRUCK d) TRACTOR. Each of them have differing

Java: Parse XML and bind all data content to a Map <K, V>

蹲街弑〆低调 提交于 2019-12-11 02:29:11
问题 I'm trying to develop a SOAP client & parser which is specific to our project. I've already finished the client and it invokes many kinds of (several different) SOAP web services and getting response SOAP message in XML format. My goal: Get the value of any node or attribute from any type of collection and it should be worked for all of my web services responses. e.g. I will call like as this: String h1 = collection.get("html/body/h1"); and h1's value should be 'StackOverflow' and come from:

Parsing with XStream - empty tags and collections

*爱你&永不变心* 提交于 2019-12-11 02:28:53
问题 I am using XStream to convert XML into domain objects, and have come by a problem. Omitting a few details, the XML looks like this : <airport> <flights> <flight>.....</flight> <flight>.....</flight> <flight>.....</flight> </flights> </airport> There can be 0 to N flight elements. The flight elements themselves contain other elements. I have created classes for airport, flights, and flight and registered them with the xstream.alias function. xstream = new XStream(); xstream.alias("airport",