Skip to content

Commit

Permalink
Merge pull request quarkusio#44457 from burl21/quarkusio#44433
Browse files Browse the repository at this point in the history
Support for short and uncommon field names like set, get, and is
gsmet authored Nov 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 73e757b + 7bbb0a8 commit 7fa4088
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ protected enum FieldKind {
MAP(true),
TYPE_VARIABLE(true);

private boolean generic;
private final boolean generic;

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

private String fieldNameFromMethod(MethodInfo methodInfo) {
String methodName = methodInfo.name();
if (methodName.equals("get") || methodName.equals("set") || methodName.equals("is")) {
return methodName;
}
if (methodName.startsWith("is")) {
return methodName.substring(2, 3).toLowerCase() + methodName.substring(3);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.quarkus.resteasy.reactive.jackson.deployment.test;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
import io.smallrye.common.annotation.NonBlocking;

// Ensures uncommon field names like "set", "get", and "is" are generated correctly.
class FieldNameSetGetPrefixResourceTest {
@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(Resource.class, Resource.UncommonBody.class).addAsResource(
new StringAsset(
"quarkus.rest.jackson.optimization.enable-reflection-free-serializers=true\n"),
"application.properties"));

@Test
void testFieldNameSetGetIsPrefix() {
RestAssured.get("/field-name-prefixes")
.then()
.statusCode(200)
.contentType("application/json")
.body("id", Matchers.equalTo("id"))
.body("set", Matchers.is(true))
.body("get", Matchers.is(true))
.body("is", Matchers.is(false))
.body("setText", Matchers.equalTo("setText"));
}

@NonBlocking
@Path("/field-name-prefixes")
private static class Resource {
@GET
public UncommonBody get() {
return new UncommonBody("id", true, true, false, "setText");
}

private record UncommonBody(String id, boolean set, boolean get, boolean is, String setText) {
}
}

}

0 comments on commit 7fa4088

Please sign in to comment.