-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide rest-client-<serialization> extensions
- Loading branch information
Showing
50 changed files
with
1,104 additions
and
119 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-rest-client-jackson-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-rest-client-jackson-deployment</artifactId> | ||
<name>Quarkus - REST Client - Jackson - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-jackson-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-rest-client-jackson</artifactId> | ||
</dependency> | ||
<!-- Do NOT include resteasy-jackson as a dependency! --> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-resteasy-deployment</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-junit5-internal</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rest-assured</groupId> | ||
<artifactId>rest-assured</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
18 changes: 18 additions & 0 deletions
18
...nt/src/main/java/io/quarkus/restclient/jackson/deployment/RestClientJacksonProcessor.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.restclient.jackson.deployment; | ||
|
||
import io.quarkus.deployment.Capabilities; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.CapabilityBuildItem; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
|
||
public class RestClientJacksonProcessor { | ||
|
||
@BuildStep | ||
void build(BuildProducer<FeatureBuildItem> feature, | ||
BuildProducer<CapabilityBuildItem> capability) { | ||
feature.produce(new FeatureBuildItem(FeatureBuildItem.REST_CLIENT_JACKSON)); | ||
|
||
capability.produce(new CapabilityBuildItem(Capabilities.REST_JACKSON)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...son/deployment/src/test/java/io/quarkus/restclient/jackson/deployment/ClientResource.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,33 @@ | ||
package io.quarkus.restclient.jackson.deployment; | ||
|
||
import java.time.Month; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RestClient; | ||
|
||
@Path("/client") | ||
public class ClientResource { | ||
|
||
@Inject | ||
@RestClient | ||
RestInterface restInterface; | ||
|
||
@GET | ||
@Path("/hello") | ||
public String hello() { | ||
DateDto dateDto = restInterface.get(); | ||
ZonedDateTime zonedDateTime = dateDto.getDate(); | ||
|
||
if (zonedDateTime.getMonth().equals(Month.NOVEMBER) | ||
&& zonedDateTime.getZone().equals(ZoneId.of("Europe/London"))) { | ||
return "OK"; | ||
} | ||
|
||
return "INVALID"; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...nt-jackson/deployment/src/test/java/io/quarkus/restclient/jackson/deployment/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,23 @@ | ||
package io.quarkus.restclient.jackson.deployment; | ||
|
||
import java.time.ZonedDateTime; | ||
|
||
public class DateDto { | ||
|
||
private ZonedDateTime date; | ||
|
||
public DateDto() { | ||
} | ||
|
||
public DateDto(ZonedDateTime date) { | ||
this.date = date; | ||
} | ||
|
||
public void setDate(ZonedDateTime date) { | ||
this.date = date; | ||
} | ||
|
||
public ZonedDateTime getDate() { | ||
return date; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...kson/deployment/src/test/java/io/quarkus/restclient/jackson/deployment/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,27 @@ | ||
package io.quarkus.restclient.jackson.deployment; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path("/hello") | ||
public class HelloResource { | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
@GET | ||
public String hello() throws JsonProcessingException { | ||
return objectMapper | ||
.writeValueAsString(new DateDto(ZonedDateTime.of(1988, 11, 17, 0, 0, 0, 0, ZoneId.of("Europe/Paris")))); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...loyment/src/test/java/io/quarkus/restclient/jackson/deployment/JacksonRestClientTest.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,28 @@ | ||
package io.quarkus.restclient.jackson.deployment; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
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.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class JacksonRestClientTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withConfigurationResource("application.properties") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(ZonedDateTimeObjectMapperCustomizer.class, DateDto.class, HelloResource.class, | ||
RestInterface.class, | ||
ClientResource.class)); | ||
|
||
@Test | ||
public void testCustomDeserialization() { | ||
RestAssured.get("/client/hello").then() | ||
.body(is("OK")); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...kson/deployment/src/test/java/io/quarkus/restclient/jackson/deployment/RestInterface.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,19 @@ | ||
package io.quarkus.restclient.jackson.deployment; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
@RegisterRestClient | ||
@Path("/hello") | ||
@RegisterClientHeaders | ||
public interface RestInterface { | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
DateDto get(); | ||
} |
43 changes: 43 additions & 0 deletions
43
...st/java/io/quarkus/restclient/jackson/deployment/ZonedDateTimeObjectMapperCustomizer.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,43 @@ | ||
package io.quarkus.restclient.jackson.deployment; | ||
|
||
import java.io.IOException; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatterBuilder; | ||
|
||
import javax.inject.Singleton; | ||
|
||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.DeserializationContext; | ||
import com.fasterxml.jackson.databind.JsonDeserializer; | ||
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 ZonedDateTimeObjectMapperCustomizer 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")))); | ||
customDateModule.addDeserializer(ZonedDateTime.class, new ZonedDateTimeEuropeLondonDeserializer()); | ||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
.registerModule(customDateModule); | ||
} | ||
|
||
public static class ZonedDateTimeEuropeLondonDeserializer extends JsonDeserializer<ZonedDateTime> { | ||
|
||
@Override | ||
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) | ||
throws IOException, JsonProcessingException { | ||
return ZonedDateTime.parse(p.getValueAsString()) | ||
.withZoneSameInstant(ZoneId.of("Europe/London")); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
extensions/rest-client-jackson/deployment/src/test/resources/application.properties
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 @@ | ||
io.quarkus.restclient.jackson.deployment.RestInterface/mp-rest/url=${test.url} |
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,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-build-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
<relativePath>../../build-parent/pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-rest-client-jackson-parent</artifactId> | ||
<name>Quarkus - REST Client - Jackson</name> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
Oops, something went wrong.