mdk_protocol.JSONParser Maven / Gradle / Ivy
/* Quark 1.0.452 run at 2016-11-11 16:09:46.008093 */
package mdk_protocol;
/**
* Convert JSON-encoded strings into objects.
*/
public class JSONParser implements io.datawire.quark.runtime.QObject {
public static quark.reflect.Class mdk_protocol_JSONParser_ref = datawire_mdk_md.Root.mdk_protocol_JSONParser_md;
public java.util.HashMap _typeToClass = io.datawire.quark.runtime.Builtins.map(new Object[]{});
public JSONParser() {}
/**
* Register a type field and the corresponding class.
*/
public void register(String type, quark.reflect.Class cls) {
((this)._typeToClass).put((type), (cls));
}
/**
* Decode a String into an Object.
*/
public Object decode(String message) {
io.datawire.quark.runtime.JSONObject json = io.datawire.quark.runtime.JSONObject.parse(message);
quark.reflect.Class cls = ((this)._typeToClass).get(((json).getObjectItem("type")).getString());
if ((cls)==(null) || ((Object)(cls) != null && ((Object) (cls)).equals(null))) {
return null;
}
Object instance = (cls).construct(new java.util.ArrayList(java.util.Arrays.asList(new Object[]{})));
quark.Functions.fromJSON(cls, instance, json);
return instance;
}
public String _getClass() {
return "mdk_protocol.JSONParser";
}
public Object _getField(String name) {
if ((name)==("_typeToClass") || ((Object)(name) != null && ((Object) (name)).equals("_typeToClass"))) {
return (this)._typeToClass;
}
return null;
}
public void _setField(String name, Object value) {
if ((name)==("_typeToClass") || ((Object)(name) != null && ((Object) (name)).equals("_typeToClass"))) {
(this)._typeToClass = (java.util.HashMap) (value);
}
}
}