java - Spring MVC PATCH method: partial updates -


i have project using spring mvc + jackson build rest service. let's have following java entity

public class myentity {     private integer id;     private boolean aboolean;     private string averybigstring;     //getter & setters } 

sometimes, want update boolean value, , don't think sending whole object big string idea update simple boolean. so, have considered using patch http method send fields need updated. so, declare following method in controller:

@requestmapping(method = requestmethod.patch) public void patch(@requestbody myvariable myvariable) {     //calling service update entity } 

the problem is: how know fields need updated? instance, if client wants update boolean, object empty "averybigstring". how supposed know user wants update boolean, not want empty string?

i have "solved" problem building custom urls. instance, following url: post /myentities/1/aboolean/true mapped method allows update boolean. problem solution is not rest compliant. don't want 100% rest compliant, not feel comfortable providing custom url update each field (especially given causes problems when want update several fields).

another solution split "myentity" multiple resources , update these resources, feel not make sense: "myentity" is plain resource, not composed of other resources.

so, there elegant way of solving problem?

you may change boolean boolean , assign null value fields don't want update. 1 not null value define field client want update.


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -