Return-Path: X-Original-To: apmail-cxf-issues-archive@www.apache.org Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 61BD4103BA for ; Fri, 2 May 2014 10:19:29 +0000 (UTC) Received: (qmail 6731 invoked by uid 500); 2 May 2014 10:19:23 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 6608 invoked by uid 500); 2 May 2014 10:19:18 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 6369 invoked by uid 99); 2 May 2014 10:19:16 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 May 2014 10:19:16 +0000 Date: Fri, 2 May 2014 10:19:15 +0000 (UTC) From: "Andrei Shakirin (JIRA)" To: issues@cxf.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (CXF-5722) JAXB generated Enum throws IllegalArgumentException by unmarshalling as @QueryParam MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/CXF-5722?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13987559#comment-13987559 ] Andrei Shakirin commented on CXF-5722: -------------------------------------- Let keep issue open until clarification request will be commented: https://java.net/jira/browse/JAX_RS_SPEC-460 > JAXB generated Enum throws IllegalArgumentException by unmarshalling as @QueryParam > ----------------------------------------------------------------------------------- > > Key: CXF-5722 > URL: https://issues.apache.org/jira/browse/CXF-5722 > Project: CXF > Issue Type: Bug > Components: JAX-RS > Affects Versions: 3.0.0-milestone2 > Reporter: Andrei Shakirin > Assignee: Andrei Shakirin > > By processing request with Query parameter, InjectionUtils tries to recognize and instantiate parameter class. > In case of Enum parameter class, InjectionUtils.handleParameter() method calls in loop following methods: "fromString", "fromValue", "valueOf" using reflection. If method returns null, it tries the next one: > if (result == null) { > // check for valueOf(String) static methods > String[] methodNames = cls.isEnum() > ? new String[] {"fromString", "fromValue", "valueOf"} > : new String[] {"valueOf", "fromString"}; > for (String mName : methodNames) { > result = evaluateFactoryMethod(value, cls, pType, mName); > if (result != null) { > break; > } > } > The problem is that factory methods in JAXB generated Enum behaves differently: > - valueOf() accepts enum identifier (not value) > - fromValue() accepts enum value > Both methods throws IllegalArgumentException by worng argument and do not return null, how current code expecting. Because formValue() is tried before valueOf(), it throws exception and valueOf() is never tried, despite of fact that it will convert the value correctly. > As a result following method throws IllegalArgumentException: > 1) method: > @GET > @Path("/enum/") > Response checkEnum(@QueryParam("car") CarType car); > 2) generated enum: > @XmlRootElement(name = "Car") > @XmlType(name = "carType") > @XmlEnum > public enum CarType { > @XmlEnumValue("Audi") > AUDI("Audi"), > @XmlEnumValue("Golf") > GOLF("Golf"), > BMW("BMW"); > private final String value; > CarType(String v) { > value = v; > } > public String value() { > return value; > } > public static CarType fromValue(String v) { > for (CarType c: CarType.values()) { > if (c.value.equals(v)) { > return c; > } > } > throw new IllegalArgumentException(v); > } > } > 3) call: > customerService.checkEnum(CarType.AUDI); -- This message was sent by Atlassian JIRA (v6.2#6252)