Skip to content

Commit 88cbed9

Browse files
committed
Align Jackson configs
1 parent d338736 commit 88cbed9

8 files changed

Lines changed: 32 additions & 8 deletions

File tree

dropwizard-app/src/main/java/bitxon/dropwizard/DropwizardApplication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import bitxon.dropwizard.errorhandler.ResourceNotFoundExceptionHandler;
1111
import bitxon.dropwizard.mapper.AccountMapper;
1212
import bitxon.dropwizard.resource.AccountResource;
13+
import com.fasterxml.jackson.databind.DeserializationFeature;
14+
import com.fasterxml.jackson.databind.SerializationFeature;
1315
import io.dropwizard.client.JerseyClientBuilder;
1416
import io.dropwizard.core.Application;
1517
import io.dropwizard.core.setup.Bootstrap;
@@ -67,6 +69,10 @@ protected void configure() {
6769
var exchangeClient = new ExchangeClient(client, configuration.getExchangeClientConfig());
6870
environment.jersey().register(exchangeClient);
6971

72+
var objectMapper = environment.getObjectMapper();
73+
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
74+
objectMapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); // not really necessary, but shows how to customize Jackson
75+
7076

7177
environment.jersey().register(AccountResource.class);
7278

dropwizard-app/src/test/java/bitxon/dropwizard/test/GetByIdDropwizardTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void getById() {
1919
.get("/accounts/{id}")
2020
.then()
2121
.statusCode(200)
22-
.body("id", is(expectedId));
22+
.body("id", is(expectedId))
23+
.body("dateOfBirth", is("1991-01-21"));
2324
//@formatter:on
2425
}
2526

micronaut-app/src/main/resources/application.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ netty:
2424
allocator:
2525
max-order: 3
2626

27+
jackson:
28+
serialization:
29+
WRITE_DATES_AS_TIMESTAMPS: false
30+
deserialization:
31+
ACCEPT_SINGLE_VALUE_AS_ARRAY: true # not really necessary, but shows how to customize Jackson
32+
2733
datasources:
2834
default:
2935
maximum-pool-size: 40 # default=10

micronaut-app/src/test/java/bitxon/micronaut/test/GetAccountByIdMicronautTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ void getById() {
2020
.get("/accounts/{id}")
2121
.then()
2222
.statusCode(200)
23-
.body("id", is(expectedId));
23+
.body("id", is(expectedId))
24+
.body("dateOfBirth", is("1991-01-21"));
2425
//@formatter:on
2526
}
2627

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package bitxon.quarkus.customization;
22

3-
import com.fasterxml.jackson.annotation.JsonInclude;
3+
import com.fasterxml.jackson.databind.DeserializationFeature;
44
import com.fasterxml.jackson.databind.ObjectMapper;
55
import io.quarkus.jackson.ObjectMapperCustomizer;
66
import jakarta.inject.Singleton;
@@ -9,6 +9,6 @@
99
public class RegisterObjectMapperCustomizer implements ObjectMapperCustomizer {
1010

1111
public void customize(ObjectMapper mapper) {
12-
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
12+
mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); // not really necessary, but shows how to customize Jackson
1313
}
1414
}

quarkus-app/src/test/java/bitxon/quarkus/test/GetAccountByIdQuarkusTest.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static io.restassured.RestAssured.given;
44
import static org.hamcrest.Matchers.hasItem;
5+
import static org.hamcrest.Matchers.is;
56

67
import io.quarkus.test.junit.QuarkusTest;
78
import org.junit.jupiter.api.Test;
@@ -11,13 +12,18 @@ public class GetAccountByIdQuarkusTest extends AbstractQuarkusTest {
1112

1213
@Test
1314
public void getById() {
15+
var expectedId = 1;
16+
1417
//@formatter:off
1518
given()
19+
.pathParam("id", expectedId)
1620
.when()
17-
.get("/accounts/1")
21+
.get("/accounts/{id}")
1822
.then()
19-
.statusCode(200);
20-
//@formatter:off
23+
.statusCode(200)
24+
.body("id", is(expectedId))
25+
.body("dateOfBirth", is("1991-01-21"));
26+
//@formatter:on
2127
}
2228

2329
@Test

spring-app/src/main/resources/application.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ management:
1010
port: 8081
1111

1212
spring:
13+
jackson:
14+
deserialization:
15+
ACCEPT_SINGLE_VALUE_AS_ARRAY: true # not really necessary, but shows how to customize Jackson
1316
datasource:
1417
hikari:
1518
maximum-pool-size: 40 # default=10

spring-app/src/test/java/bitxon/spring/test/GetAccountByIdSpringTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ void getById() {
1919
.get("/accounts/{id}")
2020
.then()
2121
.statusCode(200)
22-
.body("id", is(expectedId));
22+
.body("id", is(expectedId))
23+
.body("dateOfBirth", is("1991-01-21"));
2324
//@formatter:on
2425
}
2526

0 commit comments

Comments
 (0)