Field path handling makes no distinction between a.[] and a
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with JsonContentHandler.resolveFieldType and the FieldDescriptor paths used in the two tests, comparing a with a.[]. Confirm the intended distinction for array contents and root arrays, then update the tests and behavior to establish the chosen root-path syntax while preserving the expected compatibility decision.
Written by the indexing model from the issue text.
Description
In working on #626, it has become apparent that the lack of distinction that is made between a.[] and a is problematic. It's a subtle difference, but the former should locate the contents of the array at a, whereas the latter should locate the array itself.
The following tests illustrate the problem:
@Test
public void typeForArrayWithMixedContents() {
Object fieldType = new JsonContentHandler("{\"a\": [\"five\", 5]}".getBytes())
.resolveFieldType(new FieldDescriptor("a"));
assertThat(fieldType).isEqualTo(JsonFieldType.ARRAY);
}
@Test
public void typeForContentsOfArrayWithMixedContents() {
Object fieldType = new JsonContentHandler("{\"a\": [\"five\", 5]}".getBytes())
.resolveFieldType(new FieldDescriptor("a.[]"));
assertThat(fieldType).isEqualTo(JsonFieldType.VARIES);
}
The first test passes but the second test fails. It fails because the resolved type is ARRAY rather than VARIES.
When a payload is an array at the top level, [] is currently used to locate that array. To correct the behaviour of the test above, it would change to locating the contents of the array. This change would require the introduction of another syntax that identifies the root of the payload. An empty path is one option, another would be $. The latter would align with JSON path which uses $ to refer to the root element.
While the current behaviour is a bug, fixing it will be a breaking change for some so a balance needs to be struck. Waiting until 2.1 feels like the best approach at the moment.
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 731
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from spring-projects/spring-restdocs
-
status: waiting-for-triage
Difficulty 5/5 Over a week Newbie friendliness 45/100
spring-projects/spring-restdocs#1026 · 2 comments ·
-
status: waiting-for-votes type: enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
spring-projects/spring-restdocs#1020 · 6 comments ·
-
type: enhancement
spring-projects/spring-restdocs#995 · 1 assignee ·
-
status: blocked status: waiting-for-triage
Difficulty 4/5 3-5 days Newbie friendliness 35/100
spring-projects/spring-restdocs#953 · 7 comments ·
-
type: enhancement
Difficulty 3/5 1-2 days Newbie friendliness 45/100
All issues in spring-projects/spring-restdocs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100