Created
January 26, 2016 09:32
-
-
Save stepango/d8b0ffde18521a9e14dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new JsonBuilder<String, String>() | |
.put("$email", "mail@google.com") | |
.put("$username", "username") | |
.put("$name", "Name Name") | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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