simple-framework

Java - Convert xml to JAVA Pojo classes including java annotations(Simplexml)

拜拜、爱过 提交于 2019-12-11 06:11:30
问题 I am developing an application which uses XML as API request and response body. To fetch and parse this using retrofit, i have used SimpleXml as the converter for retrofit. But in order to create pojo classes for the corresponding XML, i could not find any online methods similar to jsonchema2pojo. And since the XML involved in the project is huge in size, it is very time consuming to create POJO classes manually. I am posting this question as an FAQ, since i had some trouble finding an easy

Java : Simple XML not parsing the xml. Gives Exception

巧了我就是萌 提交于 2019-12-11 02:13:13
问题 I am using Simple XML Serialization(simple-xml-2.6.6.jar) here to convert my XML response from webservice to POJO class. XML is as follow: <Alerts> <Alert> <CCRDataObjectID>38</CCRDataObjectID> <DateTime> <Type> <Text>Verified</Text> </Type> <ExactDateTime>2010-06-16T00:00:00Z</ExactDateTime> </DateTime> <Type> <Text>Allergy</Text> </Type> <Description> <Text>R-Tanna</Text> </Description> <Source> <Actor> <ActorID>122</ActorID> </Actor> </Source> <Reaction> <Description> <Text>rash</Text> <

Simple XML ElementListUnion - two generic lists not allowed?

时间秒杀一切 提交于 2019-12-10 19:18:05
问题 I am trying to desrialize an xml through simple framework. I have two lists whose types will be known only at runtime. So I used @ElementListUnion. Customer.java @ElementListUnion({@ElementList(inline = true,type=Thing.class),@ElementList(inline = true,type=AnotherThing.class)}) List<Object> things; @ElementListUnion({@ElementList(inline = true,type=Thing.class),@ElementList(inline = true,type=AnotherThing.class)}) List<Object> anotherthings ; But Im getting the following exception 03-20 19

SimpleXML parsing elementlist exception

三世轮回 提交于 2019-12-10 18:55:27
问题 Hi i have problem with parsing this xml : <?xml version="1.0" encoding="UTF-8"?> <Response> <Items> <Item> <TdlID>202</TdlID> <TdlDesc>1234567890</TdlDesc> <Due>2013-07-19</Due> <Done>0</Done> <Creadate>2013-07-08 23:43:51</Creadate> <UsrLogin>demouser</UsrLogin> <Prj>3211</Prj> <Chngdate>2013-07-17</Chngdate> </Item> <Item> <TdlID>218</TdlID> <TdlDesc>fghjkljh</TdlDesc> <Due>2013-07-31</Due> <Done>1</Done> <Creadate>2013-07-10 11:06:10</Creadate> <UsrLogin>demouser</UsrLogin> <Prj>abcd</Prj>

@Order annotation has no effect on the XML serialization order

帅比萌擦擦* 提交于 2019-12-10 15:46:37
问题 I'm using Retrofit 2 with a SimpleXmlConverter and I am facing an issue when creating a Soap Request Object, that is basically an element with 4 element children each one of them being different datatypes. Here is the XML output I want to produce. The element order must be respected: <prf:container> <prf:aaa>111111111</prf:aaa> <prf:bbb>true</prf:bbb> <prf:element> <prf:ddd>50</prf:ddd> <prf:eee>false</prf:eee> </prf:element> <prf:ccc>textcontent</prf:ccc> </prf:container> Now, here is my

Simple XML - 2 elements, same name different namespace

ぃ、小莉子 提交于 2019-12-10 14:53:35
问题 I need to parse a XML string into objects. I would use SimpleXML for it but i got an error, Duplicate annotation of name 'link' on field 'url' private java.lang.String com.example.rogedormans.xmlreader.XML.Alert.Channel.url . An sample XML with the same problem: <rss........> <channel> <title>The Title</title> <link>http://www.someurl.com</link> <description>Some description</description> <atom:link href="http://dunno.com/rss.xml" rel="self" type="application/rss+xml"/> .... .... </channel> <

Simple Xml - order of elements not preserved?‏

半世苍凉 提交于 2019-12-09 11:54:38
问题 I am using SimpleXml 2.6.1 in my android app. Eventhough the documentation (http://simple.sourceforge.net/download/stream/doc/javadoc/index.html?org/simpleframework/xml/Order.html) says the order of the elements in the xml are same as the way they have defined in the class file, I am always getting the order to be random in the xml. If I add few more variables, the order of the elements again changes. Adding @Order notation works, but since the class is complex with 100s of variables, I do

How to serialize a null string as a single empty tag?

时间秒杀一切 提交于 2019-12-09 10:19:43
问题 I serialize this class using the Simple XML framework: @Root public class HowToRenderEmptyTag { @Element(required=false) private String nullString; } I want to get: <howToRenderNull> <nullString/> </howToRenderNull> But I get: <howToRenderNull/> I have tried assigning an empty string: @Root public class HowToRenderEmptyTag { @Element(required=false) private String emptyString = ""; } But then I get one opening and one closing tag: <howToRenderNull> <emptyString></emptyString> <

Deserializing an XML tag with text AND subtags using Retrofit

天涯浪子 提交于 2019-12-09 07:00:09
问题 I'm using Retrofit and SimpleXML in order to parse an XML response from some public API. I've been doing pretty well with all content, till I stumbled upon XML tags that contain both free-text AND sub-tags - as illustrated by the following example: <a> Some free-style text <b>Even more text!</b> </a> In an attempt to deserialize using Simple-XML annotations, I've gone two ways. Keep in mind that basically the 'a's are a list of entry tags: The first: @ElementList(entry = "a", inline = true,

Parsing differently named elements as a single list using SIMPLE XML library for android

喜欢而已 提交于 2019-12-08 22:01:36
I was wondering if there was anyway to treat col_1,col_2...etc as a list rather than separate elements, using the SIMPLE XML Library for Android. I have been reading a bit about substitutions but I'm still confused. Current Format : <box-headers dataTable="boxscore" col_1="FINAL" col_2="1" col_3="2" col_4="3" col_5="4" col_6="5" col_7="6" col_8="7" col_9="8" col_10="9" col_11="R" col_12="H" col_13="E"> table </box-headers> I want to be able to parse out the col's as a list of some sort so I can handle any number of cols. Is this possible? As ng said before: Use a Converter for this. Simple is