java - PATCH request method: field mapping -


i'm implementing patch request method in restful service (spring, java). i'm consuming dto objects in controller methods. i'm using dozer map dto's entities.

with patch request method have obvious problem: field null value mean either entity field should updated null, or entity field should left unchanged. having looked through posts in internet, decided accept in uri parameters list of fields nulled explicitly (i'll refere list nullfields). other fields stay unchanged if received value null.

now can see 3 possible ways implement solution:

  1. to have dozer map objects usual, skipping fields null values. explicitly set fields nullfields null. have iterate on values of nullfields , invoke appropriate setter methods of entity. don't option because have change field-to-setter mapping every time add, delete or rename object fields.
  2. same above - dozer maps objects, set of fields null explicitly - using reflection. wouldn't have maintain field-to-setter mapping described in 1. have use reflection considered bad practice.
  3. get dozer skip fields included in nullfields changing mapping configurations dynamically or in other way. wasn't able find out how it. so, question is, possible?

i appreciate other ways implement patch request method. i've considered consuming json objects instead of dto's, don't quite alternative unless have no other choice.

i had similar problem patch requests, handle null values have written custom dozer mapper. can read information bypass mapping of null or empty values

the other way implement patch request given in (json) patch. also, there open source implementation available rfc java library find / apply json patches.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -