Skip to content

Commit 34150b0

Browse files
committed
bean parser: dot notation fix #486
1 parent 1da71c5 commit 34150b0

2 files changed

Lines changed: 48 additions & 5 deletions

File tree

coverage-report/src/test/java/org/jooby/issues/Issue483.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jooby.issues;
22

3+
import java.util.List;
34
import java.util.Optional;
45

56
import org.jooby.Parser;
@@ -8,6 +9,28 @@
89

910
public class Issue483 extends ServerFeature {
1011

12+
public static class Member {
13+
String firstname;
14+
15+
String lastname;
16+
17+
@Override
18+
public String toString() {
19+
return firstname + " " + lastname;
20+
}
21+
}
22+
23+
public static class Group {
24+
25+
List<Member> members;
26+
27+
@Override
28+
public String toString() {
29+
return Optional.ofNullable(members).map(it -> it.toString()).orElse("[]");
30+
}
31+
32+
}
33+
1134
public static class NullableBean {
1235

1336
String foo;
@@ -23,24 +46,44 @@ public String toString() {
2346
{
2447
parser(Parser.bean(true));
2548

26-
get("/483", req -> {
49+
get("/483/dot", req -> {
50+
return req.params().toList(Member.class);
51+
});
52+
53+
get("/483/nested", req -> {
54+
return req.params(Group.class);
55+
});
56+
57+
get("/483/null", req -> {
2758
return req.params(NullableBean.class).toString();
2859
});
2960

3061
}
3162

63+
@Test
64+
public void dotNotation() throws Exception {
65+
request()
66+
.get("/483/dot?0.firstname=Pedro&0.lastname=PicaPiedra")
67+
.expect("[Pedro PicaPiedra]");
68+
69+
request()
70+
.get("/483/nested?members.0.firstname=Pedro&members.0.lastname=PicaPiedra")
71+
.expect("[Pedro PicaPiedra]");
72+
73+
}
74+
3275
@Test
3376
public void documentNullBeanInjection() throws Exception {
3477
request()
35-
.get("/483?foo=foo")
78+
.get("/483/null?foo=foo")
3679
.expect("foonull");
3780

3881
request()
39-
.get("/483?foo=foo&bar")
82+
.get("/483/null?foo=foo&bar")
4083
.expect("fooOptional[]");
4184

4285
request()
43-
.get("/483?foo=foo&bar=bar")
86+
.get("/483/null?foo=foo&bar=bar")
4487
.expect("fooOptional[bar]");
4588
}
4689

jooby/src/main/java/org/jooby/internal/parser/bean/BeanPlan.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private List<BeanPath> compile(final Iterator<String> it, final TypeLiteral bean
186186
}
187187

188188
private List<Tuple2<String, Integer>> segments(final String path) {
189-
List<String> segments = Splitter.on(CharMatcher.anyOf("[]")).trimResults()
189+
List<String> segments = Splitter.on(CharMatcher.anyOf("[].")).trimResults()
190190
.omitEmptyStrings()
191191
.splitToList(path);
192192
List<Tuple2<String, Integer>> result = new ArrayList<>(segments.size());

0 commit comments

Comments
 (0)