I'm using dropwizard (jersey, jackson) to create a REST API and have stumbled upon some problems I can't seem to find the answer to. I would like to build an sql query based on a json file. This would be done via a map (criteria, value). I have some problems realising this:
- Calling the DAO method getUserByCriteria(Map/JSONObject) will give me this type of error: UnsupportedOperationException: No type parameters found for erased type 'interface java.util.Map[K, V]'. To bind a generic type, prefer using bindByType. OR a "No Argument factory" error which I can't seem to reproduce atm
Code:
UserResource:
@POST
@Path("/list")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public List<User> getUser(@Auth UserToken token, JSONObject json) {
return userDAO.getUserByCriteria(json);
}
UserDao:
List<User> getInvoiceByCriteria(@Bind("json") JSONObject json);
When I do get this to work, how would I go about it? My code looks like this (can't seem to get the code block formatted for this one):
@SqlQuery("SELECT * FROM user LIMIT 10")
@RegisterRowMapper(UserMapper.class)
List getUserByCriteria(@Bind("json") Map json);
And I would like to make it do something like this:
@SqlQuery("SELECT * FROM user WHERE crit1 = :crit1 AND crit2 = :crit2 LIMIT 10")
@RegisterRowMapper(UserMapper.class)
List<User> getUserByCriteria(@Bind("json") Map json){
//EXTRACT VALUES OF MAP HERE
//
};
I realise this is a pretty vague question. Problem is I'm a pretty big noob on this REST stuff and the problems I encounter aren't that common (or I'm searching for the wrong things). Any help/insight is greatly appreciated!
Xtra question regarding http/rest: I feel like this should be a GET request instead of a POST, but my Advanced Rest Client doesn't allow for a body in the GET request. I found online that this is usually not done, but allowed. Is using POST ok here?