java - Mapping XML to models when list node name and item node name are the same -
I am writing a client for an API and I am trying to map the top response to my model :
This is my InvoiceMessageCollection
@XmlRootElement (name = "invoice-message") @XmlAccessorType (XmlAccessType.NONE) applies the public class InvoiceMessageCollection Iterable & LT; InvoiceMessage & gt; {@XmlElement (name = "invoice-message") private list & lt; InvoiceMessage & gt; List = New ArrayList & lt; InvoiceMessage & gt; (); Public listing & lt; InvoiceMessage & gt; GetList () {Return List; } Public Zero Set List (List & lt; InvoiceMessage & gt; List) {this.list = list; } InputStream (Last InputStream XML) throws harvest from Public Stable Invoice Message HarvestClientException {try {JAXBContext context = JAXBContext.newInstance (InvoiceMessageCollection.class); Unmarshaller unmarshaller = context.createUnmarshaller (); Return (Invoice Message Collection); Unmasharar.Yourmaral (XML); } Hold (exception e) {New Harvest Client Exception ("Unable to parse XML in Invoice ITM category.", E); }} @ Override Public Iterator & lt; Invoice Message & gt; Iterator () {return.iter.iterator (); }} The problem is that both the list and item have the same node name, it is clearly a bug in their API because it is the only call where they have the same name, but Yet - is there any way that I can fix it and still can use JACAB?
Actual Exception Return (Invoice Message Collection) unmarshaller.unmarshal (xml); Invoice message can not be inserted in the invoice message collection. Exception in thread "main" com.enonic.harvestclient exceptions.HarvestClientException: Unable to parse XML in InvoiceItemCategory Com.enonic.harvestclient.models.InvoiceMessageCollection.fromInputStream (InvoiceMessageCollection.java 45) at com.enonic.harvestclient.DefaultHarvestClient.getInvoiceMessages (DefaultHarvestClient.java315) at com.enonic.harvestclient.Testing.main (at testing.java): 22) sun.reflect.DelegatingMethodAccessorImpl.invoke at sun.reflect.NativeMethodAccessorImpl.invoke0 (native resident method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:57) at (DelegatingMethodAccessorImpl.java:43) at java.lang. Reflect on com.intellij.rt.execution.application.AppMain.main (AppMain.java:120). Method.voke (Method.java:606) By: java.lang.ClassCastException: com.enonic.harvestclient.models. InvoiceMessage com.enonic.harvestclient.models.InvoiceMessageCollection.fromInputStream (InvoiceMessageCollection.java41) ... 7 more not be molded into com.enonic.harvestclient.models.InvoiceMessageCollection
Being the same element @XmlRootElement for both invoicing message And there will be no problem for JAXB due to @XmlElement Exception appears in its own code. Reason: java.lang.ClassCastException: can not be called at com.enonic.harvestclient.models.InvoiceCom.enonic.harvestclient.models. InvoiceMessageCollection update at com.enonic.harvestclient.models.InvoiceMessageCollection.fromInputStream (InvoiceMessageCollection.java41) ... 7 more
In my invoice message model, xml alarms are also (name = "invoices-message") because single invoices are calls to messages. From JAXB it seems that the return list is actually a message. You can not do this Instead of commenting with InvoiceMessageCollection @XmlRootElement you should use an unusual method that takes a class parameter. Invoice Message Collection IMC = Unmeshsheller.mineral (XML, invoice message removal.class) .getValue ();
Comments
Post a Comment