Skip to content

Commit 05bc84f

Browse files
philwebbwilkinsona
authored andcommitted
Add Jackson 2 smoke tests (WIP)
1 parent 6043798 commit 05bc84f

File tree

13 files changed

+303
-0
lines changed

13 files changed

+303
-0
lines changed

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ include ":smoke-test:spring-boot-smoke-test-graphql"
419419
include ":smoke-test:spring-boot-smoke-test-hateoas"
420420
include ":smoke-test:spring-boot-smoke-test-hibernate"
421421
include ":smoke-test:spring-boot-smoke-test-integration"
422+
include ":smoke-test:spring-boot-smoke-test-jackson2-mixed"
423+
include ":smoke-test:spring-boot-smoke-test-jackson2-only"
422424
include ":smoke-test:spring-boot-smoke-test-jetty"
423425
include ":smoke-test:spring-boot-smoke-test-jetty-jsp"
424426
include ":smoke-test:spring-boot-smoke-test-jetty-ssl"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java"
19+
}
20+
21+
description = "Spring Boot Jackson 2 mixed with Jackson 3 smoke test"
22+
23+
dependencies {
24+
implementation(project(":module:spring-boot-jackson2"))
25+
implementation(project(":starter:spring-boot-starter-actuator"))
26+
implementation(project(":starter:spring-boot-starter-webmvc"))
27+
28+
testImplementation(project(":starter:spring-boot-starter-test"))
29+
testImplementation(project(":starter:spring-boot-starter-webmvc-test"))
30+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jackson2.mixed;
18+
19+
import java.io.IOException;
20+
21+
import com.fasterxml.jackson.core.JsonGenerator;
22+
import com.fasterxml.jackson.databind.JsonSerializer;
23+
import com.fasterxml.jackson.databind.SerializerProvider;
24+
25+
import org.springframework.boot.jackson2.JsonComponent;
26+
27+
@SuppressWarnings("removal")
28+
@JsonComponent
29+
public class Jackson2Component {
30+
31+
public static class Serializer extends JsonSerializer<Name> {
32+
33+
@Override
34+
public void serialize(Name value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
35+
gen.writeString("JACKSON2:%s:%s".formatted(value.first(), value.last()));
36+
}
37+
38+
}
39+
40+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jackson2.mixed;
18+
19+
import tools.jackson.core.JacksonException;
20+
import tools.jackson.core.JsonGenerator;
21+
import tools.jackson.databind.SerializationContext;
22+
import tools.jackson.databind.ValueSerializer;
23+
24+
import org.springframework.boot.jackson.JsonComponent;
25+
26+
@JsonComponent
27+
public class JacksonComponent {
28+
29+
public static class Serializer extends ValueSerializer<Name> {
30+
31+
@Override
32+
public void serialize(Name value, JsonGenerator gen, SerializationContext ctxt) throws JacksonException {
33+
gen.writeString("JACKSON:%s:%s".formatted(value.first(), value.last()));
34+
}
35+
36+
}
37+
38+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jackson2.mixed;
18+
19+
public record Name(String first, String last) {
20+
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jackson2.mixed;
18+
19+
import java.util.List;
20+
21+
import org.springframework.web.bind.annotation.GetMapping;
22+
import org.springframework.web.bind.annotation.RestController;
23+
24+
@RestController
25+
public class SampleController {
26+
27+
@GetMapping("/names")
28+
List<Name> names() {
29+
return List.of(new Name("Spring", "Boot"));
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.jackson2.mixed;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.util.Assert;
22+
import org.springframework.util.ClassUtils;
23+
24+
@SpringBootApplication
25+
public class SampleJackson2MixedApplication {
26+
27+
public static void main(String[] args) {
28+
Assert.state(ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", null), "Expected Jackson 2");
29+
Assert.state(ClassUtils.isPresent("tools.jackson.databind.ObjectMapper", null), "Expected Jackson 3");
30+
SpringApplication.run(SampleJackson2MixedApplication.class, args);
31+
}
32+
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
@NullMarked
18+
package smoketest.jackson2.mixed;
19+
20+
import org.jspecify.annotations.NullMarked;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
spring.http.converters.preferred-json-mapper=jackson2
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java"
19+
}
20+
21+
description = "Spring Boot Jackson 2 without Jackson 3 smoke test"
22+
23+
dependencies {
24+
implementation(project(":module:spring-boot-jackson2"))
25+
implementation(project(":starter:spring-boot-starter-actuator"))
26+
implementation(project(":starter:spring-boot-starter-webmvc")) {
27+
exclude module: 'spring-boot-starter-jackson'
28+
}
29+
30+
testImplementation(project(":starter:spring-boot-starter-test"))
31+
testImplementation(project(":starter:spring-boot-starter-webmvc-test"))
32+
}

0 commit comments

Comments
 (0)