Skip to content

Commit b697b55

Browse files
committed
Add a passing test for #422
1 parent 961ae91 commit b697b55

File tree

4 files changed

+141
-1
lines changed

4 files changed

+141
-1
lines changed

release-notes/CREDITS-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,8 @@ David Schmidt (d-schmidt@github)
137137
* Reported #390: Unexpected attribute at string fields causes extra objects to be
138138
created in parent list
139139
(2.12.0)
140+
141+
Akop Karapetyan (0xe1f@github)
142+
143+
* Reported #422: Elements containing <CDATA/> parsed incorrectly when at the end of another element
144+
(2.12.0)

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ Project: jackson-dataformat-xml
5656
from `true` to `false`
5757
#412: Coercion from element-with-attribute-and-text only works for `String`,
5858
not other scalar types
59+
#422: Elements containing <CDATA/> parsed incorrectly when at the end of another element
60+
(reported by Akop K)
5961
#434: Add missing `ElementType.ANNOTATION_TYPE` for Jackson xml annotations
6062
to allow bundling
6163
- Add Gradle Module Metadata (https://blog.gradle.org/alignment-with-gradle-module-metadata)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package com.fasterxml.jackson.dataformat.xml.deser;
2+
3+
import java.util.List;
4+
5+
import javax.xml.stream.XMLInputFactory;
6+
7+
import com.ctc.wstx.stax.WstxInputFactory;
8+
9+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
10+
11+
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
12+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
13+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
14+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
15+
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
16+
17+
// [dataformat-xml#422]
18+
public class NonNamespaceAwareDeser422Test extends XmlTestBase
19+
{
20+
// [dataformat-xml#422]
21+
@JsonIgnoreProperties(ignoreUnknown = true) // to skip `xmlns`
22+
static class RssDocument422 {
23+
public RssChannel channel;
24+
}
25+
26+
@JsonIgnoreProperties(ignoreUnknown = true) // to skip `xmlns`
27+
static class RssChannel {
28+
public String title;
29+
public String description;
30+
@JacksonXmlProperty(localName = "link")
31+
public String siteUrl;
32+
@JacksonXmlProperty(localName = "lastBuildDate")
33+
public String updated;
34+
@JacksonXmlElementWrapper(useWrapping = false)
35+
@JacksonXmlProperty(localName = "item")
36+
public List<RssItem> items;
37+
}
38+
39+
@JsonIgnoreProperties({ "category" })
40+
static class RssItem {
41+
@JacksonXmlProperty(localName = "guid")
42+
public String localId;
43+
@JacksonXmlProperty(localName = "pubDate")
44+
public String updated;
45+
public String title;
46+
@JacksonXmlProperty(localName = "link")
47+
public String articleUrl;
48+
@JacksonXmlProperty(localName = "dc:creator")
49+
public String author;
50+
@JacksonXmlProperty(localName = "content:encoded")
51+
public String encodedContent;
52+
@JacksonXmlProperty(localName = "description")
53+
public String content;
54+
}
55+
56+
public void testBigDocIssue422() throws Exception
57+
{
58+
final XMLInputFactory xmlInputFactory = new WstxInputFactory();
59+
xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
60+
final XmlMapper xmlMapper = XmlMapper.builder(XmlFactory.builder()
61+
.inputFactory(xmlInputFactory)
62+
.build()).build();
63+
64+
final String XML =
65+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
66+
"<rss xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:content=\"http://purl.org/rss/1.0/modules/content/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:slash=\"http://purl.org/rss/1.0/modules/slash/\" xmlns:sy=\"http://purl.org/rss/1.0/modules/syndication/\" xmlns:wfw=\"http://wellformedweb.org/CommentAPI/\" version=\"2.0\">\n" +
67+
" <channel>\n" +
68+
" <title>Ars Technica</title>\n" +
69+
" <link>https://arstechnica.com</link>\n" +
70+
" <description>Serving the Technologist for more than a decade. IT news, reviews, and analysis.</description>\n" +
71+
" <lastBuildDate>Sun, 23 Aug 2020 23:48:25 +0000</lastBuildDate>\n" +
72+
" <language>en-US</language>\n" +
73+
" <sy:updatePeriod>hourly</sy:updatePeriod>\n" +
74+
" <sy:updateFrequency>1</sy:updateFrequency>\n" +
75+
" <generator>https://wordpress.org/?v=4.9.15</generator>\n" +
76+
" <image>\n" +
77+
" <url>https://cdn.arstechnica.net/wp-content/uploads/2016/10/cropped-ars-logo-512_480-32x32.png</url>\n" +
78+
" <title>Ars Technica</title>\n" +
79+
" <link>https://arstechnica.com</link>\n" +
80+
" <width>32</width>\n" +
81+
" <height>32</height>\n" +
82+
" </image>\n" +
83+
" <atom10:link xmlns:atom10=\"http://www.w3.org/2005/Atom\" rel=\"self\" type=\"application/rss+xml\" href=\"http://feeds.arstechnica.com/arstechnica/index\" />\n" +
84+
" <feedburner:info xmlns:feedburner=\"http://rssnamespace.org/feedburner/ext/1.0\" uri=\"arstechnica/index\" />\n" +
85+
" <atom10:link xmlns:atom10=\"http://www.w3.org/2005/Atom\" rel=\"hub\" href=\"http://pubsubhubbub.appspot.com/\" />\n" +
86+
" <item>\n" +
87+
" <title>Trump announces a COVID-19 Emergency Use Authorization for blood plasma</title>\n" +
88+
" <link>https://arstechnica.com/?p=1700815</link>\n" +
89+
" <pubDate>Sun, 23 Aug 2020 23:26:43 +0000</pubDate>\n" +
90+
" <dc:creator><![CDATA[John Timmer]]></dc:creator>\n" +
91+
" <category><![CDATA[Policy]]></category>\n" +
92+
" <category><![CDATA[Science]]></category>\n" +
93+
" <category><![CDATA[antibodies]]></category>\n" +
94+
" <category><![CDATA[COVID-19]]></category>\n" +
95+
" <category><![CDATA[Emergency Use Authorization]]></category>\n" +
96+
" <category><![CDATA[fda]]></category>\n" +
97+
" <category><![CDATA[plasma]]></category>\n" +
98+
" <category><![CDATA[SARS-CoV-2]]></category>\n" +
99+
" <category><![CDATA[Trump]]></category>\n" +
100+
" <guid isPermaLink=\"false\">https://arstechnica.com/?p=1700815</guid>\n" +
101+
" <description><![CDATA[Move reportedly happens over objections of health officials about limited data.]]></description>\n" +
102+
" <content:encoded><![CDATA[<div id=\"rss-wrap\">\n" +
103+
"<figure class=\"intro-image intro-left\"><img src=\"https://cdn.arstechnica.net/wp-content/uploads/2020/08/GettyImages-1220853125-800x604.jpg\" alt=\"Image of a man gesturing towards another.\"><p class=\"caption\" style=\"font-size:0.8em\"><a href=\"https://cdn.arstechnica.net/wp-content/uploads/2020/08/GettyImages-1220853125.jpg\" class=\"enlarge-link\" data-height=\"773\" data-width=\"1024\">Enlarge</a> <span class=\"sep\">/</span> Donald Trump gestures to Stephen Hahn, head of the FDA, at an earlier press conference. (credit: <a rel=\"nofollow\" class=\"caption-link\" href=\"https://www.gettyimages.com/detail/news-photo/president-donald-trump-and-stephen%C2%A0hahn-director-of-the-news-photo/1220853125?adppopup=true\">Drew Angerer</a>)</p> </figure><div><a name=\"page-1\"></a></div>\n" +
104+
"<p>Today, President Trump held a news conference to announce that the FDA has granted an Emergency Use Authorization for the treatment of COVID-19 cases using blood plasma from those formerly infected. The move comes despite significant uncertainty regarding just how effective this treatment is, and comes just days after Trump attacked the FDA for delaying its work as part of a plot to sabotage his re-election.</p>\n" +
105+
"<h2>In the blood</h2>\n" +
106+
"<p>Plasma is the liquid portion of the blood, which (among other things) contains antibodies. It has been used to treat other infections, as some antibodies can be capable of neutralizing the infecting pathogen—binding to the bacteria or virus in a way that prevents it from entering cells. Early studies have indicated that it's relatively common for those who have had a SARS-CoV-2 infection to generate antibodies that can neutralize the virus in lab tests, although the antibody response to the virus is also <a href=\"https://arstechnica.com/science/2020/06/antibody-testing-suggests-immune-response-post-covid-is-very-variable/\">highly variable</a>.</p>\n" +
107+
"<p>In the absence of any effective treatments, people started testing this \"convalescent plasma\" <a href=\"https://arstechnica.com/science/2020/03/hospitals-in-nyc-will-start-testing-therapy-using-plasma-of-those-infected/\">as early as March</a>, and testing has been expanded as the pool of post-infected individuals has continued to grow. But so far, the evidence has been mixed. One of the largest studies, led by researchers at the Mayo Clinic and including over 35,000 patients, <a href=\"https://doi.org/10.1101/2020.08.12.20169359\">did see an effect</a>, but it was a very mild one: mortality dropped from 11.9 percent in people who received plasma four days or more after starting treatment, compared with 8.7 percent if treatment was started earlier than that. But, critically, the study lacked a control group, leaving its authors talking about \"signatures of efficacy,\" rather than actual evidence of efficacy.</p></div><p><a href=\"https://arstechnica.com/?p=1700815#p3\">Read 7 remaining paragraphs</a> | <a href=\"https://arstechnica.com/?p=1700815&comments=1\">Comments</a></p><div class=\"feedflare\">\n" +
108+
"<a href=\"http://feeds.arstechnica.com/~ff/arstechnica/index?a=P614tPda1Eo:cpKHHEXnQ5w:V_sGLiPBpWU\"><img src=\"http://feeds.feedburner.com/~ff/arstechnica/index?i=P614tPda1Eo:cpKHHEXnQ5w:V_sGLiPBpWU\" border=\"0\"></img></a> <a href=\"http://feeds.arstechnica.com/~ff/arstechnica/index?a=P614tPda1Eo:cpKHHEXnQ5w:F7zBnMyn0Lo\"><img src=\"http://feeds.feedburner.com/~ff/arstechnica/index?i=P614tPda1Eo:cpKHHEXnQ5w:F7zBnMyn0Lo\" border=\"0\"></img></a> <a href=\"http://feeds.arstechnica.com/~ff/arstechnica/index?a=P614tPda1Eo:cpKHHEXnQ5w:qj6IDK7rITs\"><img src=\"http://feeds.feedburner.com/~ff/arstechnica/index?d=qj6IDK7rITs\" border=\"0\"></img></a> <a href=\"http://feeds.arstechnica.com/~ff/arstechnica/index?a=P614tPda1Eo:cpKHHEXnQ5w:yIl2AUoC8zA\"><img src=\"http://feeds.feedburner.com/~ff/arstechnica/index?d=yIl2AUoC8zA\" border=\"0\"></img></a>\n" +
109+
"</div>]]></content:encoded>\n" +
110+
" </item>\n" +
111+
" </channel>\n" +
112+
"</rss>";
113+
114+
final RssDocument422 doc = xmlMapper.readerFor(RssDocument422.class)
115+
.readValue(XML);
116+
assertNotNull(doc);
117+
RssChannel channel = doc.channel;
118+
assertNotNull(channel);
119+
assertEquals("https://arstechnica.com", channel.siteUrl);
120+
List<RssItem> items = channel.items;
121+
assertNotNull(items);
122+
assertEquals(1, items.size());
123+
RssItem item = items.get(0);
124+
assertTrue(item.encodedContent.contains("<h2>In the blood</h2>"));
125+
126+
// for debugging:
127+
/* System.err.println("XML:\n"+xmlMapper
128+
.writerWithDefaultPrettyPrinter()
129+
.writeValueAsString(doc));
130+
*/
131+
}
132+
}

src/test/java/com/fasterxml/jackson/dataformat/xml/failing/ElementWrapperViaCreator149Test.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import java.util.List;
55

66
import com.fasterxml.jackson.annotation.JsonCreator;
7-
import com.fasterxml.jackson.annotation.JsonProperty;
7+
88
import com.fasterxml.jackson.databind.ObjectMapper;
9+
910
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
1011
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
1112
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;

0 commit comments

Comments
 (0)