quarkus-quickstarts/rest-jsonb Posting a Fruit object without programmatically marshall a Fruit to JSon
See original GitHub issueIn the rest-json quickstart, the FruitResourceTest.testAdd
test case posts a JSon representation of a fruit
given()
.body("{\"name\": \"Pear\", \"description\": \"Winter fruit\"}")
It would be good to have a test that passes the Fruit
object itself
Fruit pear = new Fruit("Pear", "Winter fruit");
given()
.body(pear)
If write the previous code, the test fails because of an XML exception (which is a bit annoying for a JSon quickstart
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "org.acme.rest.json.Fruit" as an element because it is missing an @XmlRootElement annotation]
If we add the @XmlRootElement
annotation to Fruit
and change all the MediaType to XML instead of JSon it works (but hey, again, for a JSON Quickstart this is not great)
Using JSON-B I can cheat and marshall the Fruit
object programmatically to a JSon String
Jsonb jsonb = JsonbBuilder.create();
Fruit pear = new Fruit("Pear", "Winter fruit");
String pearJson = jsonb.toJson(pear);
given()
.body(pearJson)
.header("Content-Type", MediaType.APPLICATION_JSON)
Is there an easy way to just pass the Fruit object and leave Quarkus do the marhalling Object -> JSon without programmatically using JSON-B and being able to just write :
Fruit pear = new Fruit("Pear", "Winter fruit");
given()
.body(pear)
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Writing JSON REST Services - Quarkus
The solution is located in the rest-json-quickstart directory. ... The Fruit objects will be automatically serialized/deserialized by JSON-B or Jackson, ...
Read more >RESTEasy Classic - Quarkus
The Fruit objects will be automatically serialized/deserialized by JSON-B or Jackson, depending on the extension you chose when initializing the project. When a ......
Read more >Writing REST Services with RESTEasy Reactive - Quarkus
This guide explains how to write REST Services with RESTEasy Reactive in Quarkus. This is the reference guide for RESTEasy Reactive. For a...
Read more >Using the REST Client - Quarkus
there is another guide if you need to write server JSON REST APIs. Prerequisites. To complete this guide, you need: Roughly 15 minutes....
Read more >Using OpenAPI and Swagger UI - Quarkus
The solution is located in the openapi-swaggerui-quickstart directory. ... We will create a Fruit bean and a FruitResource REST resource (feel free to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like
RestAssured.objectMapper(mapper);
has been removed in 4.2.0 (and it looks like Quarkus 1.3.0, depends on this version) https://github.com/rest-assured/rest-assured/pull/1257#issuecomment-575677954 You can still useI tried to test
Without success … where the “old” way to define the default objecy mapper works (the one above)
RestAssured 4.2.0 comes with JsonB support. https://github.com/rest-assured/rest-assured/pull/1257