Tuesday, 15 April 2014

How separate unset json properties from null json properties in java and PATCH requests? -



How separate unset json properties from null json properties in java and PATCH requests? -

suppose want handle patch requests , write code that:

@requestmapping(value = "/{id}", method = requestmethod.patch) @consumes("application/json") @produces("application/json") public someresponse updatetype(@pathvariable string id, @requestbody contactdto contact) throws throwable { //extract parameters contact }

so problem how recognize parameters set patch requests? @ first obvious write this:

if (contact.gethobby() != null) { updatehobby(contact.gethobby()); }

but if want set hobby null via json or delete current contact? pass json string without hobby property , upper code not work. problem - how separate properties set null not set @ all?

the body of patch request should describe changes made on target entity. shouldn't pass entity itself.

with patch, however, enclosed entity contains set of instructions describing how resource residing on origin server should modified produce new version.

for example, if wanted remove hobby, pass json like

{"removehobby":true}

your application parse , know had alter entity removing hobby value.

java json patch

No comments:

Post a Comment