Skip to content

Commit f8dd7f1

Browse files
committed
MVC + jackson - List parameters not working fix jooby-project#1391
1 parent 5e90da5 commit f8dd7f1

File tree

5 files changed

+68
-34
lines changed

5 files changed

+68
-34
lines changed

examples/pom.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616
<build>
1717
<plugins>
18-
<!-- <plugin>-->
19-
<!-- <artifactId>maven-compiler-plugin</artifactId>-->
20-
<!-- <version>3.8.1</version>-->
21-
<!-- <configuration>-->
22-
<!-- <annotationProcessorPaths>-->
23-
<!-- <path>-->
24-
<!-- <groupId>io.jooby</groupId>-->
25-
<!-- <artifactId>jooby-apt</artifactId>-->
26-
<!-- <version>${jooby.version}</version>-->
27-
<!-- </path>-->
28-
<!-- </annotationProcessorPaths>-->
29-
<!-- </configuration>-->
30-
<!-- </plugin>-->
18+
<plugin>
19+
<artifactId>maven-compiler-plugin</artifactId>
20+
<version>3.8.1</version>
21+
<configuration>
22+
<annotationProcessorPaths>
23+
<path>
24+
<groupId>io.jooby</groupId>
25+
<artifactId>jooby-apt</artifactId>
26+
<version>${jooby.version}</version>
27+
</path>
28+
</annotationProcessorPaths>
29+
</configuration>
30+
</plugin>
3131
</plugins>
3232
</build>
3333
<dependencies>

examples/src/main/java/examples/MvcController.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
import examples.jpa.Person;
99
import io.jooby.annotations.POST;
1010
import io.jooby.annotations.Path;
11-
import io.jooby.annotations.PathParam;
12-
import io.jooby.annotations.QueryParam;
1311

1412
import java.util.List;
1513

1614
@Path("/jsonlist")
1715
public class MvcController {
1816

19-
@POST("/{id}")
20-
public List<Person> post(@PathParam String id, List<Person> people) {
17+
@POST
18+
public List<Person> post(List<Person> people) {
2119
return people;
2220
}
2321
}

examples/src/main/java/examples/WebSocketApp.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,9 @@
55
*/
66
package examples;
77

8-
import io.jooby.ExecutionMode;
98
import io.jooby.Jooby;
10-
import io.jooby.WebSocketCloseStatus;
119

1210
import java.nio.file.Paths;
13-
import java.util.concurrent.Executors;
14-
import java.util.concurrent.ScheduledExecutorService;
15-
import java.util.concurrent.TimeUnit;
16-
import java.util.concurrent.atomic.AtomicInteger;
1711

1812
public class WebSocketApp extends Jooby {
1913
{
@@ -27,21 +21,12 @@ public class WebSocketApp extends Jooby {
2721
ws.send("Got: " + msg.value());
2822
});
2923
initializer.onClose((ws, closeStatus) -> {
30-
System.out.println("Closed " + closeStatus);
24+
getLog().info("Closing with: {}", closeStatus);
3125
});
32-
33-
initializer.onError((ws, cause) -> {
34-
if (ws.isOpen()) {
35-
ws.send("error: " + cause.getMessage() );
36-
} else {
37-
ws.getContext().getRouter().getLog().error("error ", cause);
38-
}
39-
});
40-
4126
});
4227
}
4328

4429
public static void main(String[] args) {
45-
runApp(args, ExecutionMode.DEFAULT, WebSocketApp::new);
30+
runApp(args, WebSocketApp::new);
4631
}
4732
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.jooby;
2+
3+
import io.jooby.annotations.POST;
4+
import io.jooby.annotations.Path;
5+
6+
import java.util.List;
7+
8+
@Path("/1391")
9+
public class Controller1391 {
10+
11+
public static class Data1391 {
12+
private String name;
13+
14+
public String getName() {
15+
return name;
16+
}
17+
18+
public void setName(String name) {
19+
this.name = name;
20+
}
21+
}
22+
23+
@POST
24+
public List<Data1391> post(List<Data1391> data) {
25+
return data;
26+
}
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.jooby;
2+
3+
import io.jooby.json.JacksonModule;
4+
import okhttp3.MediaType;
5+
import okhttp3.RequestBody;
6+
import org.junit.jupiter.api.Test;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
public class Issue1391 {
11+
12+
@Test
13+
public void issue1391() {
14+
new JoobyRunner(app -> {
15+
app.install(new JacksonModule());
16+
app.mvc(new Controller1391());
17+
18+
}).ready(client -> {
19+
client.post("/1391", RequestBody.create("[{\"name\" : \"1392\"}]", MediaType.get("application/json")), rsp -> {
20+
assertEquals("[{\"name\":\"1392\"}]", rsp.body().string());
21+
});
22+
});
23+
}
24+
}

0 commit comments

Comments
 (0)