Skip to content

Commit 33e6869

Browse files
authored
Merge pull request #7 from henrik242/missing-constructor-2-12
Add kotlin/xml related test for regression in Jackson 2.12.0
2 parents a918b6a + 3c37745 commit 33e6869

File tree

2 files changed

+65
-4
lines changed

2 files changed

+65
-4
lines changed

pom.xml

+38-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
3+
<modelVersion>4.0.0</modelVersion>
44
<parent>
55
<groupId>com.fasterxml.jackson</groupId>
66
<artifactId>jackson-base</artifactId>
@@ -23,6 +23,7 @@
2323
<javac.target.version>1.8</javac.target.version>
2424
<scala.version>2.13</scala.version>
2525
<scala.full.version>2.13.3</scala.full.version>
26+
<kotlin.version>1.4.21</kotlin.version>
2627

2728
<!-- 13-Oct-2020, tatu: may need to occasionally work around missing Scala
2829
module snapshot version
@@ -60,6 +61,15 @@
6061
<artifactId>scala-library</artifactId>
6162
<version>${scala.full.version}</version>
6263
</dependency>
64+
<dependency>
65+
<groupId>com.fasterxml.jackson.module</groupId>
66+
<artifactId>jackson-module-kotlin</artifactId>
67+
</dependency>
68+
<dependency>
69+
<groupId>org.jetbrains.kotlin</groupId>
70+
<artifactId>kotlin-stdlib-jdk8</artifactId>
71+
<version>${kotlin.version}</version>
72+
</dependency>
6373

6474
<!-- first, try to ensure dataformats work -->
6575
<dependency>
@@ -189,7 +199,7 @@
189199
<exclude>com/fasterxml/jackson/failing/*.java</exclude>
190200
</excludes>
191201
</configuration>
192-
</plugin>
202+
</plugin>
193203
<plugin>
194204
<groupId>net.alchim31.maven</groupId>
195205
<artifactId>scala-maven-plugin</artifactId>
@@ -211,14 +221,38 @@
211221
</execution>
212222
</executions>
213223
</plugin>
224+
<plugin>
225+
<groupId>org.jetbrains.kotlin</groupId>
226+
<artifactId>kotlin-maven-plugin</artifactId>
227+
<version>${kotlin.version}</version>
228+
<executions>
229+
<execution>
230+
<id>test-compile</id>
231+
<goals>
232+
<goal>test-compile</goal>
233+
</goals>
234+
<configuration>
235+
<sourceDirs>
236+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
237+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
238+
</sourceDirs>
239+
</configuration>
240+
</execution>
241+
</executions>
242+
</plugin>
214243
<plugin>
215244
<groupId>org.apache.maven.plugins</groupId>
216245
<artifactId>maven-compiler-plugin</artifactId>
217246
<executions>
218247
<execution>
219-
<phase>compile</phase>
248+
<id>default-testCompile</id>
249+
<phase>none</phase>
250+
</execution>
251+
<execution>
252+
<id>java-test-compile</id>
253+
<phase>test-compile</phase>
220254
<goals>
221-
<goal>compile</goal>
255+
<goal>testCompile</goal>
222256
</goals>
223257
</execution>
224258
</executions>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule
2+
import com.fasterxml.jackson.dataformat.xml.XmlFactory
3+
import com.fasterxml.jackson.dataformat.xml.XmlMapper
4+
import com.fasterxml.jackson.integtest.BaseTest
5+
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
6+
import javax.xml.stream.XMLInputFactory
7+
8+
class Jackson212MissingConstructorTest : BaseTest()
9+
{
10+
/**
11+
* Succeeds in Jackson 2.11.x, but fails in Jackson 2.12.0
12+
* See https://github.com/FasterXML/jackson-module-kotlin/issues/396
13+
*/
14+
fun testMissingConstructor()
15+
{
16+
val factory = XmlFactory(XMLInputFactory.newInstance())
17+
val mapper = XmlMapper(factory, JacksonXmlModule()).registerKotlinModule()
18+
19+
val xml = "<product><stuff></stuff></product>"
20+
val product: Product = mapper.readValue(xml, Product::class.java)
21+
22+
assertEquals(Product(null), product)
23+
}
24+
25+
private data class Stuff(val str: String?)
26+
private data class Product(val stuff: Stuff?)
27+
}

0 commit comments

Comments
 (0)