Hi im trying to marshalling some xml into java class with inner classes in it but having a problem: inner classes doesn't fill outer class - their are nulls.
<forms>
<form mkgu-id="0" foreign-id="ticket-department-252-2017-12-12--0">
<data>
//some data
</data>
<rates>
<rate indicator-id="2" value-id="45">45</rate>
<rate indicator-id="13" value-id="49">49</rate>
<rate indicator-id="221" value-id="55">55</rate>
<rate indicator-id="42" value-id="60">60</rate>
<rate indicator-id="53" value-id="65">65</rate>
</rates>
</form>
</forms>
Heres rate and rates classes:
@XmlRootElement(name = "rate")
public class Rate {
@XmlAttribute(name = "indicator-id")
private int indicatorId;
@XmlAttribute(name = "value")
private int value;
@XmlElement(name = "rate")
private int rate;
rates
@XmlRootElement(name = "rates")
public class Rates {
@XmlElement
private ArrayList<Rate> rates;
And when i parse i got class implementation as String like this:
Forms{forms=[Form{mkguId=0, foreignId=ticket-department-252-2017-12-12--0, data=//some data, service=Service{id=1410073997, service='null'}, procedure=0, authority=Authority{id=1411364330, authority='null'}, date='2017-12-11 18:00:00', receivedDate='2017-12-12 07:42:31', okato='53401373000'}, rates=Rates{rates=null}}]}
some fields are not filled right. What am i missing and how to fix it?
In your class Rate
you need to annotate your field rate
with @XmlValue
, not @XmlElement
. Probably the same mistake in the Service
class. It is the same mistake in your User
class that you presented in an earlier edit of your post.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.