Skip to content

Commit

Permalink
Fix generic type handling of body parameter in RESTEasy Reactive
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 29, 2021
1 parent 81e8ea3 commit 51dd0fe
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.resteasy.reactive.jackson.deployment.test;

public class DataItem<T> {

private T content;

public T getContent() {
return content;
}

public void setContent(T content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.resteasy.reactive.jackson.deployment.test;

public class Item {

private String name;
private String email;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ public Multi<Person> getMulti0() {
return Multi.createFrom().empty();
}

@POST
@Path("/genericInput")
public String genericInputTest(DataItem<Item> item) {
return item.getContent().getName();
}

public static class UnquotedFieldsPersonBiFunction implements BiFunction<ObjectMapper, Type, ObjectWriter> {

public static final AtomicInteger count = new AtomicInteger();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.resteasy.reactive.jackson.deployment.test;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
Expand All @@ -26,6 +27,7 @@ public class SimpleJsonTest {
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(Person.class, SimpleJsonResource.class, User.class, Views.class, SuperClass.class,
DataItem.class, Item.class,
NoopReaderInterceptor.class);
}
});
Expand Down Expand Up @@ -293,4 +295,17 @@ public void testCustomSerialization() {
// a new instance should have been created
assertEquals(3, SimpleJsonResource.UnquotedFieldsPersonBiFunction.count.intValue());
}

@Test
public void testGenericInput() {
RestAssured
.with()
.body("{\"content\": {\"name\":\"foo\", \"email\":\"bar\"}}")
.contentType("application/json; charset=utf-8")
.post("/simple/genericInput")
.then()
.statusCode(200)
.contentType("text/plain")
.body(is("foo"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.resteasy.reactive.jsonb.deployment.test;

public class DataItem<T> {

private T content;

public T getContent() {
return content;
}

public void setContent(T content) {
this.content = content;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.resteasy.reactive.jsonb.deployment.test;

public class Item {

private String name;
private String email;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,10 @@ public Multi<Person> getMulti2() {
public Multi<Person> getMulti0() {
return Multi.createFrom().empty();
}

@POST
@Path("/genericInput")
public String genericInputTest(DataItem<Item> item) {
return item.getContent().getName();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.resteasy.reactive.jsonb.deployment.test;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

Expand All @@ -22,7 +23,7 @@ public class SimpleJsonTest {
@Override
public JavaArchive get() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(Person.class, SimpleJsonResource.class, SuperClass.class);
.addClasses(Person.class, SimpleJsonResource.class, SuperClass.class, DataItem.class, Item.class);
}
});

Expand Down Expand Up @@ -200,4 +201,17 @@ public void testJsonMulti() {
.contentType("application/json")
.body(Matchers.equalTo("[]"));
}

@Test
public void testGenericInput() {
RestAssured
.with()
.body("{\"content\": {\"name\":\"foo\", \"email\":\"bar\"}}")
.contentType("application/json; charset=utf-8")
.post("/simple/genericInput")
.then()
.statusCode(200)
.contentType("text/plain")
.body(is("foo"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ && isContextType(paramType.asClassType())) {
builder.setOptional(true);
} else if (convertible) {
throw new RuntimeException("Invalid parameter type '" + pt + "' used on method " + errorLocation);
} else {
elementType = toClassName(pt.arguments().get(0), currentClassInfo, actualEndpointInfo, index);
addReaderForType(additionalReaders, pt);
typeHandled = true;
}
} else if ((paramType.name().equals(PATH_SEGMENT)) && (type == ParameterType.PATH)) {
elementType = paramType.name().toString();
Expand Down

0 comments on commit 51dd0fe

Please sign in to comment.