Suresh Suresh - 18 days ago 9
reST (reStructuredText) Question

REST services PATCH API example

I am trying to call the REST Webservices PATCH API, here is My JSON payload

[
{ "op":"replace", "path":"/values/Timestamp","value":"2016-10-28T15:25:43.511Z"},
{ "op":"replace", "path":"/values/Flag", "value":true },
{ "op":"replace", "path":"/values/Flow", "value":"Flow A"},
{"op":"replace", "path":"/values/Interests", "value":[ "Sports", "Book Reading" ] }
]


JSON Value attribute has different values with different data types. and I want to prepare Entity object(Java) and convert it into JSON and call REST end point.
now
I am not very sure


which is the best suitable data type I can choose for values attribute


I have referred following links but I didn't get enough details

Android REST API using PATCH method

https://tools.ietf.org/html/rfc5789#section-2.1
http://blog.earaya.com/blog/2013/05/30/the-right-way-to-do-rest-updates/

http://williamdurand.fr/2014/02/14/please-do-not-patch-like-an-idiot/

but I didn't get enough details.

any suggestion on this is really appriciated

Answer

Got the java object from the client and created another Java class with below properties and set the values

  1. opn - string
  2. path - String
  3. value - Object

added above java objects to array list then used the GSON library to convert it into the array of JSON objects which will be accepted by patch api.

and please note the content type is application/json-patch+json