Details
-
Type:
Bug
-
Status: Resolved
-
Priority:
Minor
-
Resolution: Complete
-
Affects Version/s: 1.2.4.RELEASE
-
Fix Version/s: 1.2.5.RELEASE
-
Component/s: @ ROO SHELL, WEB MVC
-
Labels:
-
Environment:Linux
-
Reference URL:
Description
Currently the controller that is generated by web mvc all does not contain a working updateFromJson method. The id argument is never applied to the deserialised entity so that the attempted merge() ends up in a create instead of an update.
This is more than likely because the example method provided in ROO-3376 had this operation missing.
Steps to reproduce:
- Run the attached roo script to create a simple REST webapp.
roo> script --file ../ROO-3431.roo
- Start the webapp.
$ mvn tomcat:run
- Create a new Word with a POST to the webapp.
$ curl -v -XPOST -H "Content-Type:application/json" http://localhost:8080/roo-3431/words -d '{ "word": "one" }' ... < HTTP/1.1 201 Created ...
- Request the word list to make sure the new word was persisted.
$ curl -v -XGET -H "Accept:application/json" http://localhost:8080/roo-3431/words ... [{"id":1,"version":0,"word":"one"}]
- Attempt to update the word with a PUT request with the resources ID.
$ curl -v -XPUT -H "Content-Type:application/json" http://localhost:8080/roo-3431/words/1 -d '{ "word": "two", "version": 0 }' ... < HTTP/1.1 200 OK ...
- Request the word list again to see if the word with ID 1 was updated.
$ curl -v -XGET -H "Accept:application/json" http://localhost:8080/roo-3431/words ... [{"id":1,"version":0,"word":"one"},{"id":2,"version":0,"word":"two"}]
As can be seen a new entry is created instead of the word being updated. A seccond attempt at the PUT will result in a unique constraint violation.