Skip to content

Commit 02f2cb6

Browse files
authored
Merge pull request #3812 from senivam/3804
issue 3804 fix (SelectableEntityFiltering when the fields specified is . character)
2 parents 575b3b0 + 6b189b3 commit 02f2cb6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

examples/entity-filtering-selectable/src/test/java/org/glassfish/jersey/examples/entityfiltering/selectable/PersonResourceTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,28 @@ public void testFilters() throws Exception {
136136
assertThat(entity.getRegion(), nullValue());
137137
}
138138

139+
/**
140+
* Test empty (but valid) filters.
141+
* Valid empty filters are:
142+
* . ,. , .. .,
143+
*
144+
*
145+
* result is empty object (nothing is returned) but Jersey will not throw any exception
146+
*/
147+
@Test
148+
public void testEmptyFilters() throws Exception {
149+
final Person entity = target("people").path("1234")
150+
.queryParam("select", ".").request()
151+
.get(Person.class);
152+
153+
// Null values (all elements).
154+
assertThat(entity.getFamilyName(), nullValue());
155+
assertThat(entity.getGivenName(), nullValue());
156+
assertThat(entity.getAddresses(), nullValue());
157+
assertThat(entity.getPhoneNumbers(), nullValue());
158+
assertThat(entity.getRegion(), nullValue());
159+
}
160+
139161
/**
140162
* Test 2nd and 3rd level filters.
141163
*/

ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/SelectableScopeResolver.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ private Set<String> getScopesForField(final String fieldName) {
8383
final String[] fields = Tokenizer.tokenize(fieldName, ",");
8484
for (final String field : fields) {
8585
final String[] subfields = Tokenizer.tokenize(field, ".");
86+
if (subfields.length == 0) {
87+
continue;
88+
}
8689
// in case of nested path, add first level as stand-alone to ensure subgraph is added
8790
scopes.add(SelectableScopeResolver.PREFIX + subfields[0]);
8891
if (subfields.length > 1) {

0 commit comments

Comments
 (0)