Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON Patch to subresource collection results in SpelEvaluationException: Method size() cannot be found [DATAREST-1039] #1405

Closed
spring-projects-issues opened this issue Mar 31, 2017 · 2 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Mar 31, 2017

Josh Wand opened DATAREST-1039 and commented

I am trying to use JSON Patch to add a subresource to a collection.. using the canonical Post -> Comment relationship with OneToMany and ManyToOne and a PostRepository, as suggested by Oliver here:
http://stackoverflow.com/questions/25311978/posting-a-onetomany-sub-resource-association-in-spring-data-rest/25451662#25451662

and following Mathias's answer here:
http://stackoverflow.com/questions/34843297/modify-onetomany-entity-in-spring-data-rest-without-its-repository/34864254#34864254.

Using 2.6.1 (as imported by Boot 1.5.2.RELEASE):

Sending PATCH to /posts/1 with:

[{"op":"add", "path":"/comments/-", "value":{"commentText":"test comment"}}];

gives the following exception:

Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method size() cannot be found on com.example.Post type
	at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:211) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:125) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:85) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.ast.OpMinus.getValueInternal(OpMinus.java:98) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.ast.Indexer.getValueRef(Indexer.java:123) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:66) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:87) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.standard.SpelExpression.getValueType(SpelExpression.java:356) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.expression.spel.standard.SpelExpression.getValueType(SpelExpression.java:342) ~[spring-expression-4.3.7.RELEASE.jar:4.3.7.RELEASE]
	at org.springframework.data.rest.webmvc.json.patch.PatchOperation.evaluateValueFromTarget(PatchOperation.java:177) ~[spring-data-rest-webmvc-2.6.1.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.json.patch.AddOperation.perform(AddOperation.java:43) ~[spring-data-rest-webmvc-2.6.1.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.json.patch.Patch.apply(Patch.java:64) ~[spring-data-rest-webmvc-2.6.1.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.config.JsonPatchHandler.applyPatch(JsonPatchHandler.java:91) ~[spring-data-rest-webmvc-2.6.1.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.config.JsonPatchHandler.apply(JsonPatchHandler.java:83) ~[spring-data-rest-webmvc-2.6.1.RELEASE.jar:na]
	at org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.readPatch(PersistentEntityResourceHandlerMethodArgumentResolver.java:198) ~[spring-data-rest-webmvc-2.6.1.RELEASE.jar:na]

Sample project with failing tests attached.

I can't get this basic boot/restmvc project running with Kay-M1 so unable to test there


Affects: 2.6.1 (Ingalls SR1)

Attachments:

Referenced from: commits 0813faf, 9ee2d43, 9a95127, 6d8caf6

Backported to: 2.6.4 (Ingalls SR4), 2.5.11 (Hopper SR11)

1 votes, 3 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 12, 2017

Oliver Drotbohm commented

That should be fixed now. We now rather inspect the type than the object to find out about the type to unmarshal the incoming JSON into. Also we now transparently initialize uninitialized collections

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 12, 2017

Josh Wand commented

(y)(y)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants