-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Rest Client @RestForm
does not serialize enums like other parameter types
#40167
Labels
Milestone
Comments
/cc @cescoffier (rest-client), @geoand (rest-client) |
In light of this comment, I updated the demo repo and added a test case to cover curl -X POST "http://localhost:8080/restclient/bean" -d "myEnum=test" which outputs the same uppercase enum name:
|
geoand
added a commit
to geoand/quarkus
that referenced
this issue
Apr 26, 2024
geoand
added a commit
that referenced
this issue
Apr 26, 2024
Use toString for serializing enum form params in REST Client
poldinik
pushed a commit
to poldinik/quarkus
that referenced
this issue
Apr 29, 2024
gsmet
pushed a commit
to gsmet/quarkus
that referenced
this issue
May 10, 2024
Fixes: quarkusio#40167 (cherry picked from commit 730c2a5)
holly-cummins
pushed a commit
to holly-cummins/quarkus
that referenced
this issue
Jul 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
If you create a custom enum, you can implement
fromString
to deserialize a string to its appropriate enum object. Conversely, you can overridetoString
to serialize the enum to a custom string rather than the enum's name.When implementing resource endpoints in RestEASY, deserialization is respected for
@RestQuery
and@RestForm
where input strings are converted to appropriate enums. Serialization from enum to string is also respected when outputting an enum as plain text, in json, etc.When implementing Rest Client endpoints that take an enum parameter, the underlying HTTP requests should contain the enum's
toString
serialization for query params, form params, etc.Serialization is respected for Rest Client query params via
@RestQuery
.However, serialization is not respected for Rest Client form params via
@RestForm
and exhibits behavior inconsistent to the other prior examples. Form params will use the enum's name rather thantoString
output.Perhaps the code path that Client form params follow may be calling
Enum#name()
rather thantoString
?Expected behavior
In form bodies, enums should be serialized by
toString
. For example, if you had an enum:A rest client endpoint that takes
@RestForm MyEnum myEnum
should pass the following to the HTTP request's form body:Actual behavior
Form bodies will end up with the name representation of the enum:
How to Reproduce?
Demo repo is here:
https://github.com/krnhotwings/quarkus-rest-client-enum
Reproduction steps are in the README:
quarkus dev
curl
commandsExpected output
Note in the log output that the 3rd curl will make an HTTP request to httpbin with the lowercase enum serialization:
Unexpected output
However, form params will be uppercased:
Output of
uname -a
orver
Linux 6.8.6-200.fc39.x86_64
Output of
java -version
openjdk version "21.0.2" 2024-01-16
Quarkus version or git rev
3.9.4
Build tool (ie. output of
mvnw --version
orgradlew --version
)Gradle 8.6
Additional information
No response
The text was updated successfully, but these errors were encountered: