-
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.
Merge pull request #11635 from gsmet/json-naming-native
Register Jackson @JsonNaming strategies for reflection
- Loading branch information
Showing
5 changed files
with
107 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
28 changes: 28 additions & 0 deletions
28
...ests/jackson/src/main/java/io/quarkus/it/jackson/ModelWithJsonNamingStrategyResource.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.it.jackson; | ||
|
||
import java.io.IOException; | ||
|
||
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.databind.ObjectMapper; | ||
|
||
import io.quarkus.it.jackson.model.SampleResponse; | ||
|
||
@Path("/json-naming/") | ||
public class ModelWithJsonNamingStrategyResource { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public ModelWithJsonNamingStrategyResource(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public String get() throws IOException { | ||
return objectMapper.writeValueAsString(new SampleResponse("My blog post")); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
integration-tests/jackson/src/main/java/io/quarkus/it/jackson/model/SampleResponse.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,35 @@ | ||
package io.quarkus.it.jackson.model; | ||
|
||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
|
||
import io.quarkus.runtime.annotations.RegisterForReflection; | ||
|
||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class) | ||
@RegisterForReflection | ||
public class SampleResponse { | ||
|
||
private String blogTitle; | ||
|
||
public SampleResponse() { | ||
} | ||
|
||
public SampleResponse(String blogTitle) { | ||
this.blogTitle = blogTitle; | ||
} | ||
|
||
public String getBlogTitle() { | ||
return blogTitle; | ||
} | ||
|
||
public void setBlogTitle(String blogTitle) { | ||
this.blogTitle = blogTitle; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "SampleResponse{" + | ||
"blogTitle='" + blogTitle + '\'' + | ||
'}'; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ts/jackson/src/test/java/io/quarkus/it/jackson/ModelWithJsonNamingStrategyResourceIT.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; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
public class ModelWithJsonNamingStrategyResourceIT extends ModelWithJsonNamingStrategyResourceTest { | ||
|
||
// Execute the same tests but in native mode. | ||
} |
24 changes: 24 additions & 0 deletions
24
.../jackson/src/test/java/io/quarkus/it/jackson/ModelWithJsonNamingStrategyResourceTest.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,24 @@ | ||
package io.quarkus.it.jackson; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
public class ModelWithJsonNamingStrategyResourceTest { | ||
|
||
@Test | ||
public void testStrategy() throws IOException { | ||
given() | ||
.when().get("/json-naming/") | ||
.then() | ||
.statusCode(200) | ||
.body(containsString("blog_title")); | ||
} | ||
|
||
} |