Skip to content

Instantly share code, notes, and snippets.

@stepango
Created January 26, 2016 09:32
Show Gist options
  • Save stepango/d8b0ffde18521a9e14dc to your computer and use it in GitHub Desktop.
Save stepango/d8b0ffde18521a9e14dc to your computer and use it in GitHub Desktop.
new JsonBuilder<String, String>()
.put("$email", "mail@google.com")
.put("$username", "username")
.put("$name", "Name Name")
.build()
package com.utils;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
import timber.log.Timber;
public class JsonBuilder<K, V> {
private final Map<K, V> map = new HashMap<>();
public JsonBuilder<K, V> put(K key, V value) {
if (key != null && value != null) {
map.put(key, value);
}
return this;
}
public JSONObject build() {
return new JSONObject(map);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment