-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Register JsonSubTypes.Type values for native mode
- Loading branch information
Showing
8 changed files
with
119 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
29 changes: 29 additions & 0 deletions
29
integration-tests/jackson/src/main/java/io/quarkus/it/jackson/JsonSubTypesResource.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,29 @@ | ||
package io.quarkus.it.jackson; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.quarkus.it.jackson.model.Elephant; | ||
import io.quarkus.it.jackson.model.MammalFamily; | ||
import io.quarkus.it.jackson.model.Whale; | ||
|
||
@Path("jsonSubTypes") | ||
public class JsonSubTypesResource { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public JsonSubTypesResource(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@GET | ||
public String test() throws JsonProcessingException { | ||
return objectMapper.writeValueAsString(new MammalFamily(List.of( | ||
new Whale(30.0, "white"), new Elephant(10, "africa")))); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Elephant.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,5 @@ | ||
package io.quarkus.it.jackson.model; | ||
|
||
public record Elephant( | ||
int hornLength, String continent) implements Mammal { | ||
} |
15 changes: 15 additions & 0 deletions
15
integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Mammal.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,15 @@ | ||
package io.quarkus.it.jackson.model; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonTypeInfo.As.PROPERTY; | ||
import static com.fasterxml.jackson.annotation.JsonTypeInfo.Id.NAME; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
|
||
@JsonTypeInfo(use = NAME, include = PROPERTY) | ||
@JsonSubTypes({ | ||
@JsonSubTypes.Type(value = Elephant.class, name = "Elephant"), | ||
@JsonSubTypes.Type(value = Whale.class, name = "Whale"), | ||
}) | ||
public interface Mammal { | ||
} |
9 changes: 9 additions & 0 deletions
9
integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/MammalFamily.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,9 @@ | ||
package io.quarkus.it.jackson.model; | ||
|
||
import java.util.Collection; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@RegisterForReflection | ||
public record MammalFamily(Collection<Mammal> mammals) { | ||
} |
5 changes: 5 additions & 0 deletions
5
integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/Whale.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,5 @@ | ||
package io.quarkus.it.jackson.model; | ||
|
||
public record Whale( | ||
double swimSpeed, String color) implements Mammal { | ||
} |
7 changes: 7 additions & 0 deletions
7
integration-tests/jackson/src/test/java/io/quarkus/it/jackson/JsonSubTypesResourceIT.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,7 @@ | ||
package io.quarkus.it.jackson; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class JsonSubTypesResourceIT extends JsonSubTypesResourceTest { | ||
} |
27 changes: 27 additions & 0 deletions
27
integration-tests/jackson/src/test/java/io/quarkus/it/jackson/JsonSubTypesResourceTest.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.it.jackson; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.response.Response; | ||
|
||
@QuarkusTest | ||
class JsonSubTypesResourceTest { | ||
|
||
@Test | ||
void test() { | ||
Response response = given() | ||
.accept(ContentType.JSON) | ||
.when() | ||
.get("jsonSubTypes") | ||
.then() | ||
.statusCode(200) | ||
.extract().response(); | ||
assertThat(response.jsonPath().getString("mammals[0].color")).isEqualTo("white"); | ||
assertThat(response.jsonPath().getString("mammals[1].continent")).isEqualTo("africa"); | ||
} | ||
} |