Uploaded image for project: 'Spring Roo'
  1. Spring Roo
  2. ROO-3431

Generated REST controllers PUT incorrect

    Details

      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:

      1. Run the attached roo script to create a simple REST webapp.
        roo> script --file ../ROO-3431.roo
        
      2. Start the webapp.
        $ mvn tomcat:run
        
      3. 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
        ...
        
      4. 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"}]
        
      5. 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
        ...
        
      6. 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.

        Attachments

          Activity

            People

            • Assignee:
              stewarta Alan Stewart
              Reporter:
              karlbennett Karl Bennett
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: