|
|
|
|
@ -12,23 +12,23 @@ import org.json.JSONObject;
|
|
|
|
|
public class ObjectMapper {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This takes a JSON string and creates (and populates) an object of the given class
|
|
|
|
|
* with the data from that JSON string. It mimics the method signature of the jackson
|
|
|
|
|
* JSON API, so that we don't have to import the jackson library into this application.
|
|
|
|
|
* This takes a JSON string and creates (and populates) an object of the
|
|
|
|
|
* given class with the data from that JSON string. It mimics the method
|
|
|
|
|
* signature of the jackson JSON API, so that we don't have to import the
|
|
|
|
|
* jackson library into this application.
|
|
|
|
|
*
|
|
|
|
|
* @param jsonString The JSON string to parse.
|
|
|
|
|
* @param objClass The class of object we want to create.
|
|
|
|
|
* @return The instantiation of that class, populated with data from the JSON object.
|
|
|
|
|
* @return The instantiation of that class, populated with data from the
|
|
|
|
|
* JSON object.
|
|
|
|
|
* @throws IOException If there was any kind of issue.
|
|
|
|
|
*/
|
|
|
|
|
public <T> T readValue(String jsonString, Class<T> objClass) throws IOException {
|
|
|
|
|
try {
|
|
|
|
|
return readValue(new JSONObject(jsonString), objClass);
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ioe) {
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
throw ioe;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new IOException(e);
|
|
|
|
|
}
|
|
|
|
|
@ -50,17 +50,14 @@ public class ObjectMapper {
|
|
|
|
|
subObjList.add((R) readValue(jsonArray.getJSONObject(i), subObj));
|
|
|
|
|
}
|
|
|
|
|
f.set(obj, subObjList);
|
|
|
|
|
}
|
|
|
|
|
else if (a != null) {
|
|
|
|
|
} else if (a != null) {
|
|
|
|
|
f.set(obj, json.opt(((JsonProperty) a).value()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException ioe) {
|
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
|
throw ioe;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new IOException(e);
|
|
|
|
|
}
|
|
|
|
|
|