I want a simple rest client library for Java (or Scala) that let's me easily do GETs/PUTs/POSTs/DELETEs etc on a JSON REST API and deserialize the JSON responses into Java objects in a type-safe way e.g.
RestClient client = new RestClient("http://api.mycompany.com").withAuth(Auth.Basic, username, password);
// This basically deserializes the JSON response into a POJO
MyDocument[] result = client.get("/document?limit=10", MyDocument[].class);
MyFriend friend = client.post("/friend/Joe", body, MyFriend.class);
Basically I want the generic signature to be something like this for get()
e.g.
public <T> T get(String path, Class<T> responseClass)
which would do a GET request and deserialize the JSON response into a POJO of type responseClass
I did find a library that is pretty close to what I want called sitebricks but it is severely limited in its scope e.g. it does not allow me to do more uncommon HTTP verbs like PUT/PATCH/DELETE and it has no way of setting headers or even the body of a request.
Another library I found has the opposite problem - it has no way of doing basicauth and it does not serialize JSONs back into objects for you.
Did you check this? Instead of SJSON you can use Salat for serializing
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With