Skip to content

Instantly share code, notes, and snippets.

@zarinfam
Created June 25, 2019 09:18
Show Gist options
  • Save zarinfam/6de4d7b8b20a2550083c77717eacc246 to your computer and use it in GitHub Desktop.
Save zarinfam/6de4d7b8b20a2550083c77717eacc246 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
interface Json{
default <T> T as(){
return (T) this;
}
default <T> T as(Class<T> clazz){
return clazz.cast(this);
}
}
class JsObject implements Json{
private Map<String, Json> value;
JsObject(Map<String, Json> map) {
this.value = map;
}
public Map<String, Json> get() {
return value;
}
}
class JsString implements Json{
private String value;
JsString(String value) {
this.value = value;
}
public String get() {
return value;
}
}
class JsNumber implements Json{
private double value;
JsNumber(double value) {
this.value = value;
}
public double get() {
return value;
}
}
final class JsNull implements Json{
private static final JsNull instance = new JsNull();
private JsNull(){
}
public static JsNull get(){
return instance;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment