Skip to content

Commit 1497372

Browse files
committed
Merge remote-tracking branch 'FasterXML/2.x' into 3.x
2 parents e5a33b8 + ff6feb0 commit 1497372

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

src/test/kotlin/tools/jackson/module/kotlin/ReadValueTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ReadValueTest {
1515
val src = defaultMapper.createParser("null")
1616
assertThrows<DatabindException> {
1717
defaultMapper.readValue<String>(src)
18-
}.printStackTrace()
18+
}
1919
}
2020

2121
@Test
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package tools.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonCreator
4+
import com.fasterxml.jackson.annotation.JsonRootName
5+
import tools.jackson.databind.DeserializationFeature
6+
import tools.jackson.dataformat.xml.XmlMapper
7+
import tools.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper
8+
import tools.jackson.dataformat.xml.annotation.JacksonXmlProperty
9+
import tools.jackson.module.kotlin.readValue
10+
import org.junit.jupiter.api.Test
11+
import tools.jackson.module.kotlin.kotlinModule
12+
import kotlin.test.assertEquals
13+
14+
class GitHub338 {
15+
data class Properties(
16+
@JacksonXmlProperty(localName = "NEW_DATE")
17+
val newDate: String?,
18+
@JacksonXmlProperty(localName = "BC_1MONTH")
19+
val oneMonth: String?
20+
)
21+
22+
data class Content(
23+
val properties: Properties
24+
)
25+
26+
data class Entry(
27+
val id: String,
28+
val updated: String,
29+
val content: Content
30+
)
31+
32+
@JsonRootName(namespace = "http://www.w3.org/2005/Atom", value = "feed")
33+
data class Feed @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) constructor(
34+
@JacksonXmlElementWrapper(useWrapping = false)
35+
val entry: List<Entry>
36+
)
37+
38+
val xml = """
39+
<feed xml:base="http://data.treasury.gov/Feed.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
40+
<entry>
41+
<id>http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(1)</id>
42+
<updated>2020-05-08T22:36:11Z</updated>
43+
<content type="application/xml">
44+
<m:properties>
45+
<d:NEW_DATE m:type="Edm.DateTime">1997-01-02T00:00:00</d:NEW_DATE>
46+
<d:BC_1MONTH m:type="Edm.Double" m:null="true" />
47+
</m:properties>
48+
</content>
49+
</entry>
50+
<entry>
51+
<id>http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(2)</id>
52+
<updated>2020-05-08T22:36:11Z</updated>
53+
<content type="application/xml">
54+
<m:properties>
55+
<d:NEW_DATE m:type="Edm.DateTime">1996-12-31T00:00:00</d:NEW_DATE>
56+
<d:BC_1MONTH m:type="Edm.Double" m:null="true" />
57+
</m:properties>
58+
</content>
59+
</entry>
60+
</feed>
61+
""".trimIndent()
62+
63+
@Test
64+
fun test() {
65+
val mapper = XmlMapper.builder()
66+
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
67+
.addModule(kotlinModule())
68+
.build()
69+
val expected = Feed(
70+
listOf(
71+
Entry(
72+
"http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(1)",
73+
"2020-05-08T22:36:11Z",
74+
Content(Properties("1997-01-02T00:00:00", ""))
75+
),
76+
Entry(
77+
"http://data.treasury.gov/Feed.svc/DailyTreasuryYieldCurveRateData(2)",
78+
"2020-05-08T22:36:11Z",
79+
Content(Properties("1996-12-31T00:00:00", ""))
80+
)
81+
)
82+
)
83+
val actual = mapper.readValue<Feed>(xml)
84+
85+
assertEquals(expected, actual)
86+
}
87+
}

0 commit comments

Comments
 (0)