MCPcopy
hub / github.com/OpenTSDB/opentsdb / parseToObject

Method parseToObject

src/utils/JSON.java:100–116  ·  view source on GitHub ↗

Deserializes a JSON formatted string to a specific class type Note: If you get mapping exceptions you may need to provide a TypeReference @param json The string to deserialize @param pojo The class type of the object used for deserialization @return An object of the pojo type @throws

(final String json,
      final Class<T> pojo)

Source from the content-addressed store, hash-verified

98 * @throws JSONException if the data could not be parsed
99 */
100 public static final <T> T parseToObject(final String json,
101 final Class<T> pojo) {
102 if (json == null || json.isEmpty())
103 throw new IllegalArgumentException("Incoming data was null or empty");
104 if (pojo == null)
105 throw new IllegalArgumentException("Missing class type");
106
107 try {
108 return jsonMapper.readValue(json, pojo);
109 } catch (JsonParseException e) {
110 throw new IllegalArgumentException(e);
111 } catch (JsonMappingException e) {
112 throw new IllegalArgumentException(e);
113 } catch (IOException e) {
114 throw new JSONException(e);
115 }
116 }
117
118 /**
119 * Deserializes a JSON formatted byte array to a specific class type

Callers 15

serdesMethod · 0.95
serdesNullsMethod · 0.95
serdesListMethod · 0.95
parseToObjectByteNullMethod · 0.95

Calls 1

isEmptyMethod · 0.80

Tested by 15

serdesMethod · 0.76
serdesNullsMethod · 0.76
serdesListMethod · 0.76
parseToObjectByteNullMethod · 0.76