-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb16c5e
commit 6ad860c
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/test/java/com/fasterxml/jackson/dataformat/xml/failing/Issue393DeserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.fasterxml.jackson.dataformat.xml.failing; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import com.fasterxml.jackson.dataformat.xml.XmlTestBase; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; | ||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; | ||
|
||
public class Issue393DeserTest extends XmlTestBase | ||
{ | ||
@JacksonXmlRootElement(localName = "result") | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
static class Value393 { | ||
private Prices prices = new Prices(); | ||
|
||
public void setPrices(Prices prices) { | ||
this.prices = prices; | ||
} | ||
|
||
@JacksonXmlProperty(localName = "prices") | ||
public Prices getPrices() { | ||
return this.prices; | ||
} | ||
} | ||
|
||
// @JsonIgnoreProperties(ignoreUnknown = true) | ||
@JacksonXmlRootElement(localName = "prices") | ||
static class Prices { | ||
private List<Price> price = new ArrayList<Price>(); | ||
|
||
public void setPrice(List<Price> price) { | ||
this.price = price; | ||
} | ||
|
||
@JacksonXmlElementWrapper(useWrapping = false) | ||
@JacksonXmlProperty(localName = "price") | ||
public List<Price> getPrice() { | ||
return this.price; | ||
} | ||
} | ||
|
||
// @JacksonXmlRootElement(localName = "price") | ||
// @JsonIgnoreProperties(ignoreUnknown = true) | ||
static class Price { | ||
private String price; | ||
private String num; | ||
|
||
protected Price() { } | ||
public Price(String p, String n) { | ||
price = p; | ||
num = n; | ||
} | ||
|
||
public void setPrice(String price) { | ||
this.price = price; | ||
} | ||
|
||
@JacksonXmlProperty(localName = "price") | ||
public String getPrice() { | ||
return this.price; | ||
} | ||
|
||
public void setNum(String num) { | ||
this.num = num; | ||
} | ||
|
||
@JacksonXmlProperty(localName = "num") | ||
public String getNum() { | ||
return this.num; | ||
} | ||
} | ||
|
||
/* | ||
/******************************************************** | ||
/* Test methods | ||
/******************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = newMapper(); | ||
|
||
// [dataform#393] | ||
public void testDeser393() throws Exception | ||
{ | ||
// for debugging: | ||
/* | ||
Value393 input = new Value393(); | ||
Prices prices = new Prices(); | ||
prices.setPrice(Arrays.asList( | ||
new Price("100", "7.0"), | ||
new Price("100", "4.0") | ||
)); | ||
input.setPrices(prices); | ||
String xml = MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(input); | ||
System.out.println("XML:\n"+xml); | ||
*/ | ||
/* | ||
String content = //"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "\n" + | ||
"<result>\n" | ||
+ " <prices>\n" | ||
+ " <price>\n" | ||
+ " <num>100</num>\n" | ||
+ " <price>7.0</price>\n" | ||
+ " </price>\n" | ||
+ " <price>\n" | ||
+ " <num>100</num>\n" | ||
+ " <price>4.0</price>\n" | ||
+ " </price>" | ||
+ " </prices>\n" | ||
+ "</result>"; | ||
Value393 result = MAPPER.readValue(content, Value393.class); | ||
assertNotNull(result); | ||
*/ | ||
|
||
String content = | ||
"<prices>\n" | ||
+ " <price>\n" | ||
+ " <num>100</num>\n" | ||
+ " <price>7.0</price>\n" | ||
+ " </price>\n" | ||
+ " <price>\n" | ||
+ " <num>100</num>\n" | ||
+ " <price>4.0</price>\n" | ||
+ " </price>" | ||
+ "</prices>\n"; | ||
Prices result = MAPPER.readValue(content, Prices.class); | ||
assertNotNull(result); | ||
} | ||
} |