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

QueryParameterProcessor could not handle lower-case in enum string value #298

Closed
jerseyrobot opened this issue Dec 7, 2007 · 11 comments
Closed

Comments

@jerseyrobot
Copy link
Contributor

Jersey get IllegalArgumentException with query param of JAX-B generated type like:

@XmlType(name = "casingEnum")
@XmlEnum
public enum CasingEnum {

@XmlEnumValue("Upper")
UPPER("Upper"), @XmlEnumValue("Lower")
LOWER("Lower"),
@XmlEnumValue("Proper")
PROPER("Proper");
private final String value;

CasingEnum(String v)

{ value = v; }

public String value()

{ return value; }

public static CasingEnum fromValue(String v) {
for (CasingEnum c: CasingEnum.values()) {
if (c.value.equals(v))

{ return c; }

}
throw new IllegalArgumentException(v);
}
}

Environment

Operating System: All
Platform: All

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Reported by ntn@java.net

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Was assigned to sandoz@java.net

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
ntn@java.net said:
Created an attachment (id=7)
Thread dump of Enum.valueOf invocation

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
File: threaddump.txt
Attached By: ntn@java.net

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
ntn@java.net said:
IMHO, the correct fix for this is from JAX-B wsimport code generation. By using
all uppercase for enum name, there would be great chance of disconnection with
the schema-specified enumeration values. For example, how JAX-B would generate
enum class for:

<s:simpleType name="EnglishCharacter">
<s:restriction base="s:string">
<s:enumeration value="A"/>
....
<s:enumeration value="a"/>
....
</s:restriction>
</s:simpleType>

An alternate solution for this issue is make Jersey be a little more supportive
of JAX-B by also check for a method named 'fromValue' on the enum type. But
this is really a brittle contract.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
sandoz@java.net said:
The problem with relying on JAXB generated field names is that there could be
some characters in the enumeration values that are illegal as characters of
field names.

You are right about brittle contracts. I think we need to review this whole area
and see if there is a more general and less brittle way.

The following links contain more use-cases/issues in this area:

https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=294

https://jersey.dev.java.net/issues/show_bug.cgi?id=15

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
ntn@java.net said:
You are right, I totally forgot about enum names actually have general Java name
constraint. Some spi for generic type converter specified at application level
would be enough, i think.

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
sandoz@java.net said:
This is a duplicate of issue 15

      • This issue has been marked as a duplicate of 15 ***

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
Marked as duplicate on Monday, January 14th 2008, 7:29:14 pm

@jerseyrobot
Copy link
Contributor Author

@glassfishrobot Commented
This issue was imported from java.net JIRA JERSEY-26

@jerseyrobot
Copy link
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant