Skip to content

Commit

Permalink
Merge pull request quarkusio#40301 from geoand/quarkusio#40167
Browse files Browse the repository at this point in the history
Use toString for serializing enum form params in REST Client
  • Loading branch information
geoand authored Apr 26, 2024
2 parents 20f148b + 730c2a5 commit 399ba31
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public <T> Object convertParam(T value, Class<T> type, Type genericType, Annotat
} else {
// FIXME: cheating, we should generate a converter for this enum
if (value instanceof Enum) {
return ((Enum) value).name();
return value.toString();
}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ void shouldPassPathParamFromBeanParam() {
assertThat(client.beanParamWithFields(new MyBeanParamWithFields()))
.isEqualTo("restPathDefault/restPathOverridden/pathParam"
+ "/restHeaderDefault/restHeaderOverridden/headerParam"
+ "/restFormDefault/restFormOverridden/formParam"
+ "/restFormDefault/test/restFormOverridden/formParam"
+ "/restCookieDefault/restCookieOverridden/cookieParam"
+ "/restQueryDefault/restQueryOverridden/queryParam");
assertThat(client.regularParameters(
"restPathDefault", "restPathOverridden", "pathParam",
"restHeaderDefault", "restHeaderOverridden", "headerParam",
"restCookieDefault", "restCookieOverridden", "cookieParam",
"restFormDefault", "restFormOverridden", "formParam",
"restFormDefault", SomeEnum.TEST, "restFormOverridden", "formParam",
"restQueryDefault", "restQueryOverridden", "queryParam"))
.isEqualTo("restPathDefault/restPathOverridden/pathParam"
+ "/restHeaderDefault/restHeaderOverridden/headerParam"
+ "/restFormDefault/restFormOverridden/formParam"
+ "/restFormDefault/test/restFormOverridden/formParam"
+ "/restCookieDefault/restCookieOverridden/cookieParam"
+ "/restQueryDefault/restQueryOverridden/queryParam");
assertThat(client.beanParamWithProperties(new MyBeanParamWithProperties())).isEqualTo("null/null/pathParam"
+ "/null/null/headerParam"
+ "/null/null/formParam"
+ "/null/null/null/formParam"
+ "/null/null/cookieParam"
+ "/null/null/queryParam");
}
Expand All @@ -78,6 +78,7 @@ String regularParameters(@RestPath String restPathDefault,
@CookieParam("cookieParam") String cookieParam,

@RestForm String restFormDefault,
@RestForm SomeEnum someEnum,
@RestForm("restForm_Overridden") String restFormOverridden,
@FormParam("formParam") String formParam,

Expand Down Expand Up @@ -114,6 +115,8 @@ public static class MyBeanParamWithFields {

@RestForm
private String restFormDefault = "restFormDefault";
@RestForm
private SomeEnum someEnum = SomeEnum.TEST;
@RestForm("restForm_Overridden")
private String restFormOverridden = "restFormOverridden";
@FormParam("formParam")
Expand Down Expand Up @@ -210,6 +213,7 @@ public String beanParamWithFields(@RestPath String restPathDefault,
@RestHeader("restHeader_Overridden") String restHeader_Overridden,
@RestHeader("headerParam") String headerParam,
@RestForm String restFormDefault,
@RestForm String someEnum,
@RestForm String restForm_Overridden,
@RestForm String formParam,
@RestCookie String restCookieDefault,
Expand All @@ -220,7 +224,7 @@ public String beanParamWithFields(@RestPath String restPathDefault,
@RestQuery String queryParam) {
return restPathDefault + "/" + restPath_Overridden + "/" + pathParam
+ "/" + restHeaderDefault + "/" + restHeader_Overridden + "/" + headerParam
+ "/" + restFormDefault + "/" + restForm_Overridden + "/" + formParam
+ "/" + restFormDefault + "/" + someEnum + "/" + restForm_Overridden + "/" + formParam
+ "/" + restCookieDefault + "/" + restCookie_Overridden + "/" + cookieParam
+ "/" + restQueryDefault + "/" + restQuery_Overridden + "/" + queryParam;
}
Expand All @@ -234,6 +238,7 @@ public String beanParamWithProperties(@RestPath String restPathDefault,
@RestHeader("restHeader_Overridden") String restHeader_Overridden,
@RestHeader("headerParam") String headerParam,
@RestForm String restFormDefault,
@RestForm String someEnum,
@RestForm String restForm_Overridden,
@RestForm String formParam,
@RestCookie String restCookieDefault,
Expand All @@ -244,9 +249,24 @@ public String beanParamWithProperties(@RestPath String restPathDefault,
@RestQuery String queryParam) {
return restPathDefault + "/" + restPath_Overridden + "/" + pathParam
+ "/" + restHeaderDefault + "/" + restHeader_Overridden + "/" + headerParam
+ "/" + restFormDefault + "/" + restForm_Overridden + "/" + formParam
+ "/" + restFormDefault + "/" + someEnum + "/" + restForm_Overridden + "/" + formParam
+ "/" + restCookieDefault + "/" + restCookie_Overridden + "/" + cookieParam
+ "/" + restQueryDefault + "/" + restQuery_Overridden + "/" + queryParam;
}
}

public enum SomeEnum {
TEST("test");

private final String value;

SomeEnum(String value) {
this.value = value;
}

@Override
public String toString() {
return value;
}
}
}

0 comments on commit 399ba31

Please sign in to comment.