Skip to content

Instantly share code, notes, and snippets.

@zaur
Created February 3, 2013 08:07
Show Gist options
  • Save zaur/4700920 to your computer and use it in GitHub Desktop.
Save zaur/4700920 to your computer and use it in GitHub Desktop.
public class Request {
private String id = "null";
private String method = "";
private RequestParams params = new RequestParams();
public String getId() {
return id;
}
public String getMethod() {
return method;
}
public Request setId(String id) {
this.id = id;
return this;
}
public Request setMethod(String method) {
this.method = method;
return this;
}
public Request addParam(String paramName, String value) {
params.put(paramName, value);
return this;
}
public Request addParam(String param, Object object) {
params.put(param, object);
return this;
}
public String toJson() {
ObjectMapper objectMapper = new ObjectMapper();
try {
return objectMapper.writeValueAsString(this);
} catch (IOException e) {
e.printStackTrace();
Log.e("JSON_GEN", e.getMessage());
}
return "";
}
private class RequestParams {
private Map<String, Object> params = new HashMap<String, Object>();
public void put(String paramName, Object object) {
params.put(paramName, object);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment