Skip to content

Commit b3bb13c

Browse files
FieteOtimtebeek
andauthored
[JacksonJavaxToJakarta] Rewrite JaxbAnnotationModule to JakartaXmlBindAnnotationModule (#654)
* write test case for jaxbannotation module rewriting * declare a ChangeType step for rewriting the FQTN * Add missing classpath entry for before source --------- Co-authored-by: Tim te Beek <[email protected]>
1 parent 962b76c commit b3bb13c

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ dependencies {
5656
testRuntimeOnly("com.fasterxml.jackson.datatype:jackson-datatype-jsr353")
5757
testRuntimeOnly("com.fasterxml.jackson.core:jackson-core")
5858
testRuntimeOnly("com.fasterxml.jackson.core:jackson-databind")
59+
testRuntimeOnly("com.fasterxml.jackson.module:jackson-module-jaxb-annotations")
5960
testRuntimeOnly("org.apache.johnzon:johnzon-core:1.2.18")
6061
testRuntimeOnly("org.codehaus.groovy:groovy:latest.release")
6162
testRuntimeOnly("jakarta.annotation:jakarta.annotation-api:2.1.1")

src/main/resources/META-INF/rewrite/jakarta-ee-9.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,9 @@ recipeList:
918918
- org.openrewrite.java.ChangeType:
919919
oldFullyQualifiedTypeName: com.fasterxml.jackson.datatype.jsr353.JSR353Module
920920
newFullyQualifiedTypeName: com.fasterxml.jackson.datatype.jsonp.JSONPModule
921+
- org.openrewrite.java.ChangeType:
922+
oldFullyQualifiedTypeName: com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule
923+
newFullyQualifiedTypeName: com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule
921924

922925
---
923926
type: specs.openrewrite.org/v1beta/recipe

src/test/java/org/openrewrite/java/migrate/jakarta/JacksonJavaxtoJakartaTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.junit.jupiter.api.Test;
1919
import org.openrewrite.DocumentExample;
20+
import org.openrewrite.Issue;
2021
import org.openrewrite.config.Environment;
2122
import org.openrewrite.java.JavaParser;
2223
import org.openrewrite.test.RecipeSpec;
@@ -294,4 +295,40 @@ private JSONPModule getModule() {
294295
)
295296
);
296297
}
298+
299+
@Issue("https://github.com/openrewrite/rewrite-migrate-java/issues/652")
300+
@Test
301+
void thatJaxbAnnotationModuleIsRewritten() {
302+
rewriteRun(
303+
spec -> spec.parser(JavaParser.fromJavaVersion().classpath(
304+
"jackson-core",
305+
"jackson-databind",
306+
"jackson-module-jaxb-annotations")),
307+
//language=java
308+
java(
309+
"""
310+
import com.fasterxml.jackson.databind.ObjectMapper;
311+
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
312+
313+
public class JacksonTest {
314+
void foo() {
315+
ObjectMapper mapper = new ObjectMapper();
316+
mapper.registerModule(new JaxbAnnotationModule());
317+
}
318+
}
319+
""",
320+
"""
321+
import com.fasterxml.jackson.databind.ObjectMapper;
322+
import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule;
323+
324+
public class JacksonTest {
325+
void foo() {
326+
ObjectMapper mapper = new ObjectMapper();
327+
mapper.registerModule(new JakartaXmlBindAnnotationModule());
328+
}
329+
}
330+
"""
331+
)
332+
);
333+
}
297334
}

0 commit comments

Comments
 (0)