#CartoDB Java Client
##Description Tiny CartoDB Java client that can be instantiated as regular (public) or secured (private). Once instantiated, you can send queries to CartoDB and get a JSON string as response.
##Usage
//Access to your public table
CartoDBClientIF cartoDBCLient= new CartoDBClient("youraccount");
System.out.println(cartoDBCLient.executeQuery("SELECT * FROM yourtable LIMIT 1"));
//Access to your private table or update your table
CartoDBClientIF cartoDBCLient= new SecuredCartoDBClient("youraccount","yourpassword","consumerKey","consumerSecret");
System.out.println(cartoDBCLient.executeQuery("UPDATE yourtable SET yourvalue = 'test' WHERE yourid = 1"));
###Use resulting JSON as Java object To transform your JSON string into real Java object, you can use a combination of json.org and Apache Bean utils. You could also use Jackson`s ObjectMapper, which is easier to use but a little bit slower on very simple JSON string (based on my own test). Here is an example using Jackson's ObjectMapper:
//this object is expensive to create so keep the reference
ObjectMapper jacksonMapper = new ObjectMapper();
CartoDBResponse<OccurrenceModel> response = jacksonMapper.readValue(json, new TypeReference<CartoDBResponse<OccurrenceModel>>(){});
My CartoDBResponse is now filled with a List of OccurrenceModel object, which represents the result of my query. Note that OccurrenceModel need to follow the JavaBean specifications. TypeReference is only a Wrapper to help the ObjectMapper manage Java Generics.
##Dependencies Included in lib folder
##TODO
- Include error JSON on HTTP response 400.
- executeQuery(sql) with a List of Java beans as return type