-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for java.time.Instant params in RESTEasy Reactive
Address: #21675 (comment) (cherry picked from commit d0cda63)
- Loading branch information
Showing
5 changed files
with
82 additions
and
1 deletion.
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
27 changes: 27 additions & 0 deletions
27
.../org/jboss/resteasy/reactive/server/core/parameters/converters/InstantParamConverter.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 org.jboss.resteasy.reactive.server.core.parameters.converters; | ||
|
||
import java.time.Instant; | ||
|
||
public class InstantParamConverter implements ParameterConverter { | ||
|
||
@Override | ||
public Object convert(Object value) { | ||
return Instant.parse(value.toString()); | ||
} | ||
|
||
public static class Supplier implements ParameterConverterSupplier { | ||
|
||
public Supplier() { | ||
} | ||
|
||
@Override | ||
public ParameterConverter get() { | ||
return new InstantParamConverter(); | ||
} | ||
|
||
@Override | ||
public String getClassName() { | ||
return InstantParamConverter.class.getName(); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../src/test/java/org/jboss/resteasy/reactive/server/vertx/test/simple/InstantParamTest.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,38 @@ | ||
package org.jboss.resteasy.reactive.server.vertx.test.simple; | ||
|
||
import io.restassured.RestAssured; | ||
import java.time.Duration; | ||
import java.time.Instant; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import org.hamcrest.Matchers; | ||
import org.jboss.resteasy.reactive.RestQuery; | ||
import org.jboss.resteasy.reactive.server.vertx.test.framework.ResteasyReactiveUnitTest; | ||
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; | ||
|
||
public class InstantParamTest { | ||
|
||
@RegisterExtension | ||
static ResteasyReactiveUnitTest test = new ResteasyReactiveUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(HelloResource.class)); | ||
|
||
@Test | ||
public void test() { | ||
RestAssured.get("/hello?instant=1984-08-08T01:02:03Z") | ||
.then().statusCode(200).body(Matchers.equalTo("hello#1984-08-09T01:02:03Z")); | ||
} | ||
|
||
@Path("hello") | ||
public static class HelloResource { | ||
|
||
@GET | ||
public String helloQuery(@RestQuery Instant instant) { | ||
return "hello#" + instant.plus(Duration.ofDays(1)).toString(); | ||
} | ||
} | ||
|
||
} |