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.
- Loading branch information
Showing
14 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...n/resources/codestarts/quarkus/examples/resteasy-jackson-example/base/README.md
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,3 @@ | ||
== RESTEasy JSON serialisation using Jackson | ||
|
||
Guide: https://quarkus.io/guides/rest-json |
12 changes: 12 additions & 0 deletions
12
...son/src/main/resources/codestarts/quarkus/examples/resteasy-jackson-example/codestart.yml
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,12 @@ | ||
name: resteasy-jackson-example | ||
ref: resteasy-jackson | ||
type: code | ||
tags: example | ||
language: | ||
base: | ||
dependencies: | ||
- io.quarkus:quarkus-resteasy | ||
- io.quarkus:quarkus-resteasy-jackson | ||
test-dependencies: | ||
- io.rest-assured:rest-assured | ||
|
14 changes: 14 additions & 0 deletions
14
.../examples/resteasy-jackson-example/java/src/main/java/org/acme/resteasyjackson/Fruit.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,14 @@ | ||
package org.acme.resteasyjackson; | ||
|
||
public class Fruit { | ||
public String name; | ||
public String description; | ||
|
||
public Fruit() { | ||
} | ||
|
||
public Fruit(String name, String description) { | ||
this.name = name; | ||
this.description = description; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...kson-example/java/src/main/java/org/acme/resteasyjackson/FruitObjectMapperCustomizer.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,16 @@ | ||
package org.acme.resteasyjackson; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.quarkus.jackson.ObjectMapperCustomizer; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class FruitObjectMapperCustomizer implements ObjectMapperCustomizer { | ||
|
||
@Override | ||
public void customize(ObjectMapper objectMapper) { | ||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...s/resteasy-jackson-example/java/src/main/java/org/acme/resteasyjackson/FruitResource.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.acme.resteasyjackson; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.MediaType; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.Set; | ||
|
||
@Path("/resteasy-jackson/fruits") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public class FruitResource { | ||
|
||
private final Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>())); | ||
|
||
public FruitResource() { | ||
fruits.add(new Fruit("Apple", "Winter fruit")); | ||
fruits.add(new Fruit("Pineapple", "Tropical fruit")); | ||
fruits.add(new Fruit("Strawberry", null)); | ||
} | ||
|
||
@GET | ||
public Set<Fruit> list() { | ||
return fruits; | ||
} | ||
|
||
@POST | ||
public Set<Fruit> add(Fruit fruit) { | ||
fruits.add(fruit); | ||
return fruits; | ||
} | ||
|
||
@DELETE | ||
public Set<Fruit> delete(Fruit fruit) { | ||
fruits.removeIf(existingFruit -> existingFruit.name.contentEquals(fruit.name)); | ||
return fruits; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...son-example/java/src/native-test/java/org/acme/resteasyjackson/NativeFruitResourceIT.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 org.acme.resteasyjackson; | ||
|
||
import io.quarkus.test.junit.NativeImageTest; | ||
|
||
@NativeImageTest | ||
public class NativeFruitResourceIT extends FruitResourceTest { | ||
|
||
// Execute the same tests but in native mode. | ||
} |
50 changes: 50 additions & 0 deletions
50
...steasy-jackson-example/java/src/test/java/org/acme/resteasyjackson/FruitResourceTest.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,50 @@ | ||
package org.acme.resteasyjackson; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.Matchers.containsInAnyOrder; | ||
|
||
@QuarkusTest | ||
public class FruitResourceTest { | ||
|
||
@Test | ||
public void testList() { | ||
given() | ||
.when().get("/resteasy-jackson/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body("$.size()", is(3), | ||
"name", containsInAnyOrder("Apple", "Pineapple", "Strawberry"), | ||
"description", containsInAnyOrder("Winter fruit", "Tropical fruit", null)); | ||
} | ||
|
||
@Test | ||
public void testAdd() { | ||
given() | ||
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}") | ||
.header("Content-Type", MediaType.APPLICATION_JSON) | ||
.when() | ||
.post("/resteasy-jackson/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body("$.size()", is(4), | ||
"name", containsInAnyOrder("Apple", "Pineapple", "Strawberry", "Pear"), | ||
"description", containsInAnyOrder("Winter fruit", "Tropical fruit", null, "Winter fruit")); | ||
|
||
given() | ||
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}") | ||
.header("Content-Type", MediaType.APPLICATION_JSON) | ||
.when() | ||
.delete("/resteasy-jackson/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body("$.size()", is(3), | ||
"name", containsInAnyOrder("Apple", "Pineapple", "Strawberry"), | ||
"description", containsInAnyOrder("Winter fruit", "Tropical fruit", null)); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...xamples/resteasy-jackson-example/kotlin/src/main/kotlin/org/acme/resteasyjackson/Fruit.kt
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,3 @@ | ||
package org.acme.resteasyjackson | ||
|
||
data class Fruit(val name: String, val description: String?) |
13 changes: 13 additions & 0 deletions
13
...on-example/kotlin/src/main/kotlin/org/acme/resteasyjackson/FruitObjectMapperCustomizer.kt
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,13 @@ | ||
package org.acme.resteasyjackson | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import io.quarkus.jackson.ObjectMapperCustomizer | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class FruitObjectMapperCustomizer : ObjectMapperCustomizer { | ||
override fun customize(objectMapper: ObjectMapper) { | ||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL) | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...resteasy-jackson-example/kotlin/src/main/kotlin/org/acme/resteasyjackson/FruitResource.kt
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,31 @@ | ||
package org.acme.resteasyjackson | ||
|
||
import javax.ws.rs.* | ||
import javax.ws.rs.core.MediaType | ||
|
||
@Path("/resteasy-jackson/fruits") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
class FruitResource { | ||
|
||
private val fruits: MutableSet<Fruit> = mutableSetOf( | ||
Fruit("Apple", "Winter fruit"), | ||
Fruit("Pineapple", "Tropical fruit"), | ||
Fruit("Strawberry", null) | ||
) | ||
|
||
@GET | ||
fun list() = fruits | ||
|
||
@POST | ||
fun add(fruit: Fruit): Set<Fruit> { | ||
fruits.add(fruit) | ||
return fruits | ||
} | ||
|
||
@DELETE | ||
fun delete(fruit: Fruit): Set<Fruit> { | ||
fruits.removeIf { existingFruit: Fruit -> existingFruit.name.contentEquals(fruit.name) } | ||
return fruits | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...n-example/kotlin/src/native-test/kotlin/org/acme/resteasyjackson/NativeFruitResourceIT.kt
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,6 @@ | ||
package org.acme.resteasyjackson | ||
|
||
import io.quarkus.test.junit.NativeImageTest | ||
|
||
@NativeImageTest | ||
class NativeFruitResourceIT : FruitResourceTest() |
48 changes: 48 additions & 0 deletions
48
...easy-jackson-example/kotlin/src/test/kotlin/org/acme/resteasyjackson/FruitResourceTest.kt
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,48 @@ | ||
package org.acme.resteasyjackson | ||
|
||
import io.quarkus.test.junit.QuarkusTest | ||
import io.restassured.RestAssured.given | ||
import org.hamcrest.CoreMatchers.`is` | ||
import org.hamcrest.Matchers | ||
import org.junit.jupiter.api.Test | ||
import javax.ws.rs.core.MediaType | ||
|
||
@QuarkusTest | ||
class FruitResourceTest { | ||
|
||
@Test | ||
fun testList() { | ||
given() | ||
.`when`()["/resteasy-jackson/fruits"] | ||
.then() | ||
.statusCode(200) | ||
.body("$.size()", `is`(3), | ||
"name", Matchers.containsInAnyOrder("Apple", "Pineapple", "Strawberry"), | ||
"description", Matchers.containsInAnyOrder("Winter fruit", "Tropical fruit", null)) | ||
} | ||
|
||
@Test | ||
fun testAdd() { | ||
given() | ||
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}") | ||
.header("Content-Type", MediaType.APPLICATION_JSON) | ||
.`when`() | ||
.post("/resteasy-jackson/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body("$.size()", `is`(4), | ||
"name", Matchers.containsInAnyOrder("Apple", "Pineapple", "Strawberry", "Pear"), | ||
"description", Matchers.containsInAnyOrder("Winter fruit", "Tropical fruit", null, "Winter fruit")) | ||
given() | ||
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}") | ||
.header("Content-Type", MediaType.APPLICATION_JSON) | ||
.`when`() | ||
.delete("/resteasy-jackson/fruits") | ||
.then() | ||
.statusCode(200) | ||
.body("$.size()", `is`(3), | ||
"name", Matchers.containsInAnyOrder("Apple", "Pineapple", "Strawberry"), | ||
"description", Matchers.containsInAnyOrder("Winter fruit", "Tropical fruit", null)) | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -13,3 +13,4 @@ metadata: | |
- "web" | ||
- "serialization" | ||
status: "stable" | ||
codestart: "resteasy-jackson" |
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