forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#7142 from geoand/quarkusio#7116
Ensure that user provided ObjectMapperCustomizer objects always have higher priority
- Loading branch information
Showing
8 changed files
with
161 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...nsions/resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/DateDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.resteasy.jackson; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class DateDto { | ||
@JsonProperty("current_date") | ||
private ZonedDateTime currentDate; | ||
|
||
public void setCurrentDate(ZonedDateTime currentDate) { | ||
this.currentDate = currentDate; | ||
} | ||
|
||
public ZonedDateTime getCurrentDate() { | ||
return currentDate; | ||
} | ||
|
||
public DateDto(ZonedDateTime currentDate) { | ||
this.currentDate = currentDate; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
.../resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/HelloResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.resteasy.jackson; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path("/hello") | ||
public class HelloResource { | ||
|
||
@GET | ||
public DateDto hello() { | ||
return new DateDto(ZonedDateTime.now()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/MultipleTimeModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.quarkus.resteasy.jackson; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
// this test really belongs in the jackson module, but it's been added here to avoid test classpath issues | ||
public class MultipleTimeModuleTest { | ||
|
||
@RegisterExtension | ||
static QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(TimeCustomizer.class, DateDto.class, HelloResource.class)); | ||
|
||
@Test | ||
public void testDateIsAlwaysInTheExpectedFormat() { | ||
verifyExpectedResult(); | ||
|
||
modifyResource(); | ||
verifyExpectedResult(); | ||
|
||
modifyResource(); | ||
verifyExpectedResult(); | ||
|
||
modifyResource(); | ||
verifyExpectedResult(); | ||
} | ||
|
||
private void verifyExpectedResult() { | ||
RestAssured.get("/hello").then() | ||
.statusCode(200) | ||
.body(containsString("Z"), not(containsString("+"))); | ||
} | ||
|
||
private void modifyResource() { | ||
TEST.modifySourceFile("TimeCustomizer.java", s -> s.replace("hello", | ||
"hello2")); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...resteasy-jackson/deployment/src/test/java/io/quarkus/resteasy/jackson/TimeCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.quarkus.resteasy.jackson; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.fasterxml.jackson.datatype.jsr310.ser.ZonedDateTimeSerializer; | ||
|
||
import io.quarkus.jackson.ObjectMapperCustomizer; | ||
|
||
@Singleton | ||
public class TimeCustomizer implements ObjectMapperCustomizer { | ||
|
||
@Override | ||
public void customize(ObjectMapper objectMapper) { | ||
JavaTimeModule customDateModule = new JavaTimeModule(); | ||
customDateModule.addSerializer(ZonedDateTime.class, new ZonedDateTimeSerializer( | ||
new DateTimeFormatterBuilder().appendInstant(0).toFormatter().withZone(ZoneId.of("Z")))); | ||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
.registerModule(customDateModule); | ||
} | ||
} |