Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonpath: fix different number of ObjectMapper modules between JVM an… #3583

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ List<ReflectiveClassBuildItem> registerReflectiveClassBuildItems() {
reflectiveClassBuildItems.add(new ReflectiveClassBuildItem(false, false, JsonPathAnnotationExpressionFactory.class));
reflectiveClassBuildItems.add(new ReflectiveClassBuildItem(true, false, JsonPath.class));
reflectiveClassBuildItems.add(new ReflectiveClassBuildItem(false, false, JacksonJsonAdapter.class));
reflectiveClassBuildItems
.add(new ReflectiveClassBuildItem(false, false, "com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule"));

return reflectiveClassBuildItems;
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/jsonpath/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.commons.lang3.StringUtils;
import org.jboss.logging.Logger;

import static org.apache.camel.jsonpath.JsonPathConstants.HEADER_JSON_ENCODING;
Expand Down Expand Up @@ -133,19 +134,21 @@ public void setHeaderWithJsonPathExpressionEvaluatingAnotherHeaderShouldSucceed(

@Path("/getAuthorsFromJsonStream")
@GET
@Produces(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public List<?> getAuthorsFromJsonStream(byte[] jsonBytes, @QueryParam("encoding") String encoding) throws IOException {
public String getAuthorsFromJsonStream(byte[] jsonBytes, @QueryParam("encoding") String encoding) throws IOException {
LOG.debugf("Getting authors from JsonStream with encoding '%s' and %d bytes", encoding, jsonBytes.length);

List<?> bookTitles;
try (ByteArrayInputStream jsonStream = new ByteArrayInputStream(jsonBytes)) {
if (encoding == null) {
return producerTemplate.requestBody("direct:getAuthorsFromJsonStream", jsonStream, List.class);
bookTitles = producerTemplate.requestBody("direct:getAuthorsFromJsonStream", jsonStream, List.class);
} else {
return producerTemplate.requestBodyAndHeader("direct:getAuthorsFromJsonStream", jsonStream,
bookTitles = producerTemplate.requestBodyAndHeader("direct:getAuthorsFromJsonStream", jsonStream,
HEADER_JSON_ENCODING, encoding, List.class);
}
}
return StringUtils.join(bookTitles, "-");
}

@Path("/splitInputJsonThenWriteAsStringShouldSucceed")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,39 @@
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.Matchers.is;

@QuarkusTest
class JsonPathCharsetsTest {

@Test
public void transformBooksUTF16BEShouldReturnTwoAuthors() throws IOException {
byte[] body = IOUtils.resourceToByteArray("/booksUTF16BE.json");
String[] authors = given().body(body).get("/jsonpath/getAuthorsFromJsonStream").then().statusCode(200).extract()
.as(String[].class);
assertEquals(2, authors.length);
assertEquals("Sayings of the Century", authors[0]);
assertEquals("Sword of Honour", authors[1]);
given().body(body)
.get("/jsonpath/getAuthorsFromJsonStream")
.then()
.statusCode(200)
.body(is("Sayings of the Century-Sword of Honour"));
}

@Test
public void transformBooksUTF16LEShouldReturnTwoAuthors() throws IOException {
byte[] body = IOUtils.resourceToByteArray("/booksUTF16LE.json");
String[] authors = given().body(body).get("/jsonpath/getAuthorsFromJsonStream").then().statusCode(200).extract()
.as(String[].class);
assertEquals(2, authors.length);
assertEquals("Sayings of the Century", authors[0]);
assertEquals("Sword of Honour", authors[1]);
given().body(body)
.get("/jsonpath/getAuthorsFromJsonStream")
.then().statusCode(200)
.body(is("Sayings of the Century-Sword of Honour"));
}

@Test
public void transformBooksIso_8859_1_ShouldReturnTwoAuthors() throws IOException {
byte[] body = IOUtils.resourceToByteArray("/germanbooks-iso-8859-1.json");
String[] authors = given().queryParam("encoding", "ISO-8859-1").body(body).get("/jsonpath/getAuthorsFromJsonStream")
.then().statusCode(200).extract().as(String[].class);
assertEquals(2, authors.length);
assertEquals("Joseph und seine Brüder", authors[0]);
assertEquals("Götzendämmerung", authors[1]);
given().queryParam("encoding", "ISO-8859-1")
.body(body)
.get("/jsonpath/getAuthorsFromJsonStream")
.then()
.statusCode(200)
.body(is("Joseph und seine Brüder-Götzendämmerung"));
}

}