Skip to content

Commit 7fa4088

Browse files
authored
Merge pull request #44457 from burl21/#44433
Support for short and uncommon field names like set, get, and is
2 parents 73e757b + 7bbb0a8 commit 7fa4088

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

extensions/resteasy-reactive/rest-jackson/deployment/src/main/java/io/quarkus/resteasy/reactive/jackson/deployment/processor/JacksonCodeGenerator.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ protected enum FieldKind {
161161
MAP(true),
162162
TYPE_VARIABLE(true);
163163

164-
private boolean generic;
164+
private final boolean generic;
165165

166166
FieldKind(boolean generic) {
167167
this.generic = generic;
@@ -281,7 +281,7 @@ private Type fieldType() {
281281
if (isPublicField()) {
282282
return fieldInfo.type();
283283
}
284-
if (methodInfo.name().startsWith("set")) {
284+
if (methodInfo.parametersCount() == 1 && methodInfo.name().startsWith("set")) {
285285
return methodInfo.parameterType(0);
286286
}
287287
return methodInfo.returnType();
@@ -304,6 +304,9 @@ private String fieldName() {
304304

305305
private String fieldNameFromMethod(MethodInfo methodInfo) {
306306
String methodName = methodInfo.name();
307+
if (methodName.equals("get") || methodName.equals("set") || methodName.equals("is")) {
308+
return methodName;
309+
}
307310
if (methodName.startsWith("is")) {
308311
return methodName.substring(2, 3).toLowerCase() + methodName.substring(3);
309312
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.quarkus.resteasy.reactive.jackson.deployment.test;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
6+
import org.hamcrest.Matchers;
7+
import org.jboss.shrinkwrap.api.ShrinkWrap;
8+
import org.jboss.shrinkwrap.api.asset.StringAsset;
9+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.RegisterExtension;
12+
13+
import io.quarkus.test.QuarkusUnitTest;
14+
import io.restassured.RestAssured;
15+
import io.smallrye.common.annotation.NonBlocking;
16+
17+
// Ensures uncommon field names like "set", "get", and "is" are generated correctly.
18+
class FieldNameSetGetPrefixResourceTest {
19+
@RegisterExtension
20+
static QuarkusUnitTest test = new QuarkusUnitTest()
21+
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
22+
.addClasses(Resource.class, Resource.UncommonBody.class).addAsResource(
23+
new StringAsset(
24+
"quarkus.rest.jackson.optimization.enable-reflection-free-serializers=true\n"),
25+
"application.properties"));
26+
27+
@Test
28+
void testFieldNameSetGetIsPrefix() {
29+
RestAssured.get("/field-name-prefixes")
30+
.then()
31+
.statusCode(200)
32+
.contentType("application/json")
33+
.body("id", Matchers.equalTo("id"))
34+
.body("set", Matchers.is(true))
35+
.body("get", Matchers.is(true))
36+
.body("is", Matchers.is(false))
37+
.body("setText", Matchers.equalTo("setText"));
38+
}
39+
40+
@NonBlocking
41+
@Path("/field-name-prefixes")
42+
private static class Resource {
43+
@GET
44+
public UncommonBody get() {
45+
return new UncommonBody("id", true, true, false, "setText");
46+
}
47+
48+
private record UncommonBody(String id, boolean set, boolean get, boolean is, String setText) {
49+
}
50+
}
51+
52+
}

0 commit comments

Comments
 (0)