java - Unable to deserialize list directly inside rootelement using Jackson XML -


I am unable to cancel a list which is a basic directory of the original element, I tried different things is. / P>

My code:

  Private static class card {@JacksonXmlElementWrapper (local name = "card") Private list & lt; Cards & gt; Leaves; Public listing & lt; Cards & gt; GetCards () {new ArrayList back & lt; & Gt; (Card); }} Private Static Class Card {@JsonProperty ("name") The name of the private string; @Jasonproperty ("image") private string image; @Jesonproperty ("Cardtype") Type Private String Card; Private Last Maps & lt; String, integer & gt; Resources = New Hashmap & lt; & Gt; (); Private Boolean duplicate resource = false; Personal Final List & lt; String & gt; Duplicate Resourcenames = New Arrestists & lt; & Gt; (); @JasonAndNetter Private Zero addResource (last string name, last object value) {if (resources.containsKey (name)) {duplicateResources = true; DuplicateResourceNames.add (name); } Resources.put (name, Integer.parseInt (value.toString ())); } Public string getName () {return name; } Public string getImage () {returns image; } Public string getCardType () {type of return card; } @JasonAngator Public Map & lt; String, integer & gt; GetResources (if {duplicate resources} {new uncheck card loading expansion ("resource" + names of duplicate resources + "are duplicate entries"); } Return to the new Hushmap & lt; & Gt; (Resources); }}  

and:

  ObjectMapper xmlMapper = new XmlMapper (); Card card = xmlMapper.readValue (path.toFile (), card.class);  

While attempting to deserialize the following XML:

  & lt; Cards & gt; & Lt; Cards & gt; & Lt; Name & gt; Trial & lt; / Name & gt; & Lt; Image & gt; & Lt; / Image & gt; & Lt; CardType & gt; Trial & lt; / CardType & gt; & Lt; / Card & gt; & Lt; / Card & gt;  

This returns the error as follows:

com.cardshifter.core.cardloader.CardLoadingException: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException : Unrecognized field "source": [card: \ user \ frank \ dropbox \ netbeans project \ cardshipper \ cardshifter "card" (class com.cardshifter.core.cardloader.xmlCardLoader $ Cards), unknown (a known property: "card ")) Is not marked as the core \ target \ test classes \ com \ cardshifter \ core \ cardloader \ single card.xml; Line: 3, column: 9] (through reference series: com.cardshifter.core.cardloader.Cards ["card"])

and then look at the error:

  com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: unrecognized field "card" (class comCardshifter .core coded loader.xml card loader $ card)   

It does not say that "> your query Second, after deciding on this, here's how I resolved your entire loading:

  Private Static class card {@JacksonXmlElementWrapper ( Local name = "card") @Jesonproperty ("card") Private list & lt; card & gt; card = new arrelistist & lt; & gt; (); @JasonSetter Public Zero Set Card (CardCard) {this.card .add (card);}}  

setCard method simply tells Jackson that if he has to face it, then give it to card , and then you provide the method that adds it to the array.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -