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

Use toString for serializing enum form params in REST Client #40301

Merged
merged 1 commit into from
Apr 26, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
Loading