Created
June 25, 2019 09:18
-
-
Save zarinfam/6de4d7b8b20a2550083c77717eacc246 to your computer and use it in GitHub Desktop.
Created with Copy to Gist
This file contains hidden or 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
| 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