Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a well-typed Scala (or Java) library to consume JSON Web APIs? [closed]

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.

like image 477
pathikrit Avatar asked Sep 19 '12 04:09

pathikrit


1 Answers

Did you check this? Instead of SJSON you can use Salat for serializing

like image 78
Sergey Passichenko Avatar answered Oct 23 '22 02:10

Sergey Passichenko