question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

quarkus-quickstarts/rest-jsonb Posting a Fruit object without programmatically marshall a Fruit to JSon

See original GitHub issue

In 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:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
danielpetismecommented, Mar 22, 2020

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 use

RestAssured.config = RestAssured.config().objectMapperConfig(
  ObjectMapperConfig.objectMapperConfig().defaultObjectMapper(mapper)
);

I tried to test

RestAssured.config = RestAssured.config.objectMapperConfig(
    ObjectMapperConfig.objectMapperConfig().defaultObjectMapperType(ObjectMapperType.JSON)
);

Without success … where the “old” way to define the default objecy mapper works (the one above)

groovy.lang.MissingMethodException: No signature of method: org.eclipse.yasson.internal.JsonBinding.writeObject() is applicable for argument types: (com.mycompany.myapp.web.rest.vm.LoginVM, StringWriter) values: [LoginVM{username='admin', rememberMe=null}, ]
0reactions
CrystalMethodcommented, Feb 7, 2020

RestAssured 4.2.0 comes with JsonB support. https://github.com/rest-assured/rest-assured/pull/1257

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found