Java - How to accomplish partial updating of an entity from a map or JsonObject? -


i'm using jax-rs in project, use @post partial update consumes json.
my code this:

@path("{id}") @post @consumes(mediatype.application_json) public response edit(@pathparam("id") long id, map map /*or jsonobject*/) {     product product = productservice.getbyid(id);      if (map.containskey("name")) {         product.setname(string.valueof(map.get("name")));     }     if (map.containskey("description")) {         product.setdescription(string.valueof(map.get("description")));     }      // ....      product = productservice.save(product);     return response.ok(product, mediatype.application_json).build(); } 

but not elegant, , gets cumbersome number of attributes increases. so, tried automate mapping using apache beanutils:

beanutils.populate(product, map); 

but if want filter attributes should not changed, example request might try change id sending { id: 666 }.
or if want values before setting attributes, example json might contains string should converted date first.

what solutions? there known practices problem? or there lib or framework tackles problem?

btw, i'm trying avoid using dtos, , if use dtos question still remains.

thank you.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -