Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 028ace9

Browse files
committed
Add repro project for SPR-13375
1 parent ed5bd19 commit 028ace9

File tree

7 files changed

+338
-0
lines changed

7 files changed

+338
-0
lines changed

SPR-13375/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Repro project for SPR-13375
2+
3+
Run `MvcTest#test()` against Spring Framework 4.2.0.RELEASE to reproduce the issue
4+
or against 4.2.1.BUILD-SNAPSHOT to see it fixed.
5+
6+

SPR-13375/pom.xml

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-13375</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<name>Spring MVC Issue Reproduction Project</name>
8+
<packaging>jar</packaging>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
13+
<java.version>1.8</java.version>
14+
<spring.version>4.2.1.BUILD-SNAPSHOT</spring.version>
15+
<slf4j.version>1.7.5</slf4j.version>
16+
</properties>
17+
18+
<dependencies>
19+
<!-- Spring Framework -->
20+
<dependency>
21+
<groupId>org.springframework</groupId>
22+
<artifactId>spring-context</artifactId>
23+
<version>${spring.version}</version>
24+
<exclusions>
25+
<!-- Exclude Commons Logging in favor of SLF4j -->
26+
<exclusion>
27+
<groupId>commons-logging</groupId>
28+
<artifactId>commons-logging</artifactId>
29+
</exclusion>
30+
</exclusions>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework</groupId>
34+
<artifactId>spring-webmvc</artifactId>
35+
<version>${spring.version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-test</artifactId>
40+
<version>${spring.version}</version>
41+
</dependency>
42+
43+
<!-- Logging -->
44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-api</artifactId>
47+
<version>${slf4j.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.slf4j</groupId>
51+
<artifactId>jcl-over-slf4j</artifactId>
52+
<version>${slf4j.version}</version>
53+
<scope>runtime</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.slf4j</groupId>
57+
<artifactId>slf4j-log4j12</artifactId>
58+
<version>${slf4j.version}</version>
59+
<scope>runtime</scope>
60+
</dependency>
61+
<dependency>
62+
<groupId>log4j</groupId>
63+
<artifactId>log4j</artifactId>
64+
<version>1.2.17</version>
65+
<scope>runtime</scope>
66+
</dependency>
67+
68+
<!-- Servlet API -->
69+
<dependency>
70+
<groupId>javax.servlet</groupId>
71+
<artifactId>javax.servlet-api</artifactId>
72+
<version>3.0.1</version>
73+
</dependency>
74+
75+
<dependency>
76+
<groupId>com.fasterxml.jackson.core</groupId>
77+
<artifactId>jackson-databind</artifactId>
78+
<version>2.6.1</version>
79+
</dependency>
80+
81+
<!-- Test -->
82+
<dependency>
83+
<groupId>junit</groupId>
84+
<artifactId>junit</artifactId>
85+
<version>4.11</version>
86+
<scope>test</scope>
87+
</dependency>
88+
</dependencies>
89+
90+
<build>
91+
<plugins>
92+
<plugin>
93+
<groupId>org.apache.maven.plugins</groupId>
94+
<artifactId>maven-compiler-plugin</artifactId>
95+
<version>2.5.1</version>
96+
<configuration>
97+
<source>${java.version}</source>
98+
<target>${java.version}</target>
99+
</configuration>
100+
</plugin>
101+
<plugin>
102+
<groupId>org.apache.maven.plugins</groupId>
103+
<artifactId>maven-dependency-plugin</artifactId>
104+
<version>2.8</version>
105+
<executions>
106+
<execution>
107+
<id>install</id>
108+
<phase>install</phase>
109+
<goals>
110+
<goal>sources</goal>
111+
</goals>
112+
</execution>
113+
</executions>
114+
</plugin>
115+
<plugin>
116+
<groupId>org.apache.maven.plugins</groupId>
117+
<artifactId>maven-eclipse-plugin</artifactId>
118+
<version>2.8</version>
119+
<configuration>
120+
<downloadSources>true</downloadSources>
121+
<downloadJavadocs>false</downloadJavadocs>
122+
<wtpversion>2.0</wtpversion>
123+
</configuration>
124+
</plugin>
125+
<plugin>
126+
<groupId>org.apache.maven.plugins</groupId>
127+
<artifactId>maven-surefire-plugin</artifactId>
128+
<version>2.12.4</version>
129+
<configuration>
130+
<includes>
131+
<include>**/*Tests.java</include>
132+
<include>**/*Test.java</include>
133+
</includes>
134+
<excludes>
135+
<exclude>**/*Abstract*.java</exclude>
136+
</excludes>
137+
</configuration>
138+
</plugin>
139+
</plugins>
140+
</build>
141+
142+
<repositories>
143+
<repository>
144+
<id>spring-maven-snapshot</id>
145+
<name>Springframework Maven Snapshot Repository</name>
146+
<url>http://repo.spring.io/snapshot</url>
147+
<snapshots>
148+
<enabled>true</enabled>
149+
</snapshots>
150+
</repository>
151+
</repositories>
152+
153+
</project>
154+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2002-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.issues;
18+
19+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
20+
21+
@JsonDeserialize(using = PersonDeserializer.class)
22+
public class Person {
23+
24+
private String name;
25+
26+
public Person(String name) {
27+
this.name = name;
28+
}
29+
30+
public String getName() {
31+
return this.name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2002-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.issues;
18+
19+
import org.springframework.http.MediaType;
20+
import org.springframework.stereotype.Controller;
21+
import org.springframework.web.bind.annotation.RequestBody;
22+
import org.springframework.web.bind.annotation.RequestMapping;
23+
import org.springframework.web.bind.annotation.RequestMethod;
24+
import org.springframework.web.bind.annotation.ResponseBody;
25+
26+
@Controller
27+
public class PersonController {
28+
29+
@RequestMapping(method = RequestMethod.POST,
30+
value = "/person",
31+
consumes = MediaType.APPLICATION_JSON_VALUE,
32+
produces = MediaType.TEXT_PLAIN_VALUE
33+
)
34+
@ResponseBody
35+
public String person(@RequestBody Person person) {
36+
return person.getName();
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2002-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.issues;
18+
19+
import java.io.IOException;
20+
21+
import com.fasterxml.jackson.core.JsonParser;
22+
import com.fasterxml.jackson.core.JsonProcessingException;
23+
import com.fasterxml.jackson.core.ObjectCodec;
24+
import com.fasterxml.jackson.databind.DeserializationContext;
25+
import com.fasterxml.jackson.databind.JsonNode;
26+
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
27+
28+
public class PersonDeserializer extends StdDeserializer<Person> {
29+
30+
public PersonDeserializer() {
31+
super(Person.class);
32+
}
33+
34+
@Override
35+
public Person deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException {
36+
ObjectCodec oc = parser.getCodec();
37+
JsonNode node = oc.readTree(parser);
38+
return new Person(node.get("n").asText());
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2002-2015 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.issues;
18+
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
22+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
23+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
24+
25+
import org.springframework.http.MediaType;
26+
import org.springframework.test.context.web.WebAppConfiguration;
27+
import org.springframework.test.web.servlet.MockMvc;
28+
import org.springframework.test.web.servlet.ResultActions;
29+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
30+
31+
@WebAppConfiguration
32+
public class MvcTest {
33+
34+
private MockMvc mockMvc;
35+
36+
private PersonController controller;
37+
38+
@Before
39+
public void setup() {
40+
controller = new PersonController();
41+
mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
42+
}
43+
44+
@Test
45+
public void test() throws Exception {
46+
ResultActions result = mockMvc.perform(post("/person")
47+
.content("{\"n\": \"foo\"}")
48+
.contentType(MediaType.APPLICATION_JSON)
49+
.accept(MediaType.TEXT_PLAIN));
50+
51+
result.andExpect(status().isOk()).andExpect(content().string("foo"));
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
log4j.rootCategory=INFO, stdout
2+
3+
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4+
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5+
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
6+
7+
log4j.category.org.springframework.web=DEBUG

0 commit comments

Comments
 (0)