Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 5976f56

Browse files
author
Adam Lindenthal
committed
Merge pull request #119 from oscarguindzberg/master
Deal with primitive array types
2 parents 3909277 + 5a97220 commit 5976f56

File tree

7 files changed

+428
-1
lines changed

7 files changed

+428
-1
lines changed

ext/bean-validation/src/main/java/org/glassfish/jersey/server/validation/internal/ValidationHelper.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,25 @@ private static String getViolationInvalidValue(final Object invalidValue) {
9999
}
100100

101101
if (invalidValue.getClass().isArray()) {
102-
return Arrays.toString((Object[]) invalidValue);
102+
if (invalidValue instanceof Object[]) {
103+
return Arrays.toString((Object[]) invalidValue);
104+
} else if (invalidValue instanceof boolean[]) {
105+
return Arrays.toString((boolean[]) invalidValue);
106+
} else if (invalidValue instanceof byte[]) {
107+
return Arrays.toString((byte[]) invalidValue);
108+
} else if (invalidValue instanceof char[]) {
109+
return Arrays.toString((char[]) invalidValue);
110+
} else if (invalidValue instanceof double[]) {
111+
return Arrays.toString((double[]) invalidValue);
112+
} else if (invalidValue instanceof float[]) {
113+
return Arrays.toString((float[]) invalidValue);
114+
} else if (invalidValue instanceof int[]) {
115+
return Arrays.toString((int[]) invalidValue);
116+
} else if (invalidValue instanceof long[]) {
117+
return Arrays.toString((long[]) invalidValue);
118+
} else if (invalidValue instanceof short[]) {
119+
return Arrays.toString((short[]) invalidValue);
120+
}
103121
}
104122

105123
return invalidValue.toString();
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44+
<modelVersion>4.0.0</modelVersion>
45+
46+
<parent>
47+
<groupId>org.glassfish.jersey.tests.integration</groupId>
48+
<artifactId>project</artifactId>
49+
<version>2.14-SNAPSHOT</version>
50+
</parent>
51+
52+
<artifactId>jersey-2689</artifactId>
53+
<packaging>war</packaging>
54+
<name>jersey-tests-integration-jersey-2689</name>
55+
56+
<description>Servlet integration test - JERSEY-2689 - Problem with validation errors on primitive type arrays</description>
57+
58+
<dependencies>
59+
<dependency>
60+
<groupId>org.glassfish.jersey.containers</groupId>
61+
<artifactId>jersey-container-servlet-core</artifactId>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.glassfish.jersey.ext</groupId>
65+
<artifactId>jersey-bean-validation</artifactId>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>com.fasterxml.jackson.core</groupId>
70+
<artifactId>jackson-core</artifactId>
71+
<version>2.4.0</version>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.fasterxml.jackson.core</groupId>
75+
<artifactId>jackson-annotations</artifactId>
76+
<version>2.4.0</version>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.fasterxml.jackson.core</groupId>
80+
<artifactId>jackson-databind</artifactId>
81+
<version>2.4.0</version>
82+
</dependency>
83+
<dependency>
84+
<groupId>com.fasterxml.jackson.jaxrs</groupId>
85+
<artifactId>jackson-jaxrs-json-provider</artifactId>
86+
<version>2.4.0</version>
87+
</dependency>
88+
89+
<dependency>
90+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
91+
<artifactId>jersey-test-framework-provider-external</artifactId>
92+
<scope>test</scope>
93+
</dependency>
94+
</dependencies>
95+
96+
<build>
97+
<plugins>
98+
<plugin>
99+
<groupId>org.apache.maven.plugins</groupId>
100+
<artifactId>maven-compiler-plugin</artifactId>
101+
</plugin>
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-failsafe-plugin</artifactId>
105+
</plugin>
106+
<plugin>
107+
<groupId>org.mortbay.jetty</groupId>
108+
<artifactId>jetty-maven-plugin</artifactId>
109+
</plugin>
110+
</plugins>
111+
</build>
112+
113+
</project>
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.tests.integration.jersey2689;
41+
42+
import java.util.HashSet;
43+
import java.util.Set;
44+
45+
import org.glassfish.jersey.server.ResourceConfig;
46+
import org.glassfish.jersey.server.ServerProperties;
47+
48+
import com.fasterxml.jackson.databind.ObjectMapper;
49+
import com.fasterxml.jackson.databind.SerializationFeature;
50+
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
51+
52+
/**
53+
* @author Oscar Guindzberg
54+
*
55+
*/
56+
public class Jersey2689 extends ResourceConfig {
57+
58+
public Jersey2689() {
59+
// Set package to look for resources in
60+
packages("org.glassfish.jersey.tests.integration.jersey2689");
61+
62+
this.property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
63+
64+
// create custom ObjectMapper
65+
ObjectMapper mapper = new ObjectMapper();
66+
mapper.enable(SerializationFeature.INDENT_OUTPUT);
67+
68+
// create JsonProvider to provide custom ObjectMapper
69+
JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
70+
provider.setMapper(mapper);
71+
this.register(provider);
72+
73+
}
74+
75+
76+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.glassfish.jersey.tests.integration.jersey2689;
2+
3+
import javax.validation.Valid;
4+
import javax.ws.rs.POST;
5+
import javax.ws.rs.Path;
6+
7+
@Path("/")
8+
public class Resource {
9+
@POST
10+
@Path("/post-bean")
11+
public void processBean(@Valid SampleBean bean) {
12+
//do-nothing
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.glassfish.jersey.tests.integration.jersey2689;
2+
3+
import org.hibernate.validator.constraints.NotEmpty;
4+
5+
public class SampleBean {
6+
7+
@NotEmpty
8+
private byte[] array;
9+
10+
public byte[] getArray() {
11+
return array;
12+
}
13+
public void setArray(byte[] array) {
14+
this.array = array;
15+
}
16+
17+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<web-app version="2.5"
44+
xmlns="http://java.sun.com/xml/ns/javaee"
45+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
46+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
47+
48+
<servlet>
49+
<servlet-name>testServlet1</servlet-name>
50+
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
51+
<init-param>
52+
<param-name>javax.ws.rs.Application</param-name>
53+
<param-value>org.glassfish.jersey.tests.integration.jersey2689.Jersey2689</param-value>
54+
</init-param>
55+
<load-on-startup>1</load-on-startup>
56+
</servlet>
57+
58+
<servlet-mapping>
59+
<servlet-name>testServlet1</servlet-name>
60+
<url-pattern>/*</url-pattern>
61+
</servlet-mapping>
62+
63+
</web-app>

0 commit comments

Comments
 (0)