|
|
|
|
@ -73,17 +73,30 @@ public class JSON extends AbstractComponent {
|
|
|
|
|
*/
|
|
|
|
|
public <T> T parse(String json, Class<T> klass) {
|
|
|
|
|
try {
|
|
|
|
|
return getObjectMapper().readValue(json, klass);
|
|
|
|
|
return getObjectMapper().readValue(notEmpty(json, "json"), klass);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
throw parsingException(json, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static RuntimeException parsingException(String json, Exception e) {
|
|
|
|
|
Throwable cause = rootCause(e);
|
|
|
|
|
String msg = cause.getLocalizedMessage();
|
|
|
|
|
log(JSON.class).debug("{} while parsing the following string:\n{}", msg, json);
|
|
|
|
|
return runtimeException(cause);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**JSON 문자열을 파싱하여 주어진 클래스의 객체로 변환한다.
|
|
|
|
|
* @param <T> 클래스 유형
|
|
|
|
|
* @param json JSON 문자열
|
|
|
|
|
* @param typeRef TypeReference
|
|
|
|
|
* @return 문자열을 파싱하여 변환한 객체
|
|
|
|
|
*/
|
|
|
|
|
public <T> T parse(String json, TypeReference<T> typeRef) {
|
|
|
|
|
try {
|
|
|
|
|
return getObjectMapper().readValue(json, typeRef);
|
|
|
|
|
return getObjectMapper().readValue(notEmpty(json, "json"), typeRef);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
throw parsingException(json, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -95,15 +108,21 @@ public class JSON extends AbstractComponent {
|
|
|
|
|
*/
|
|
|
|
|
public <T> T parse(InputStream input, Class<T> klass) {
|
|
|
|
|
try {
|
|
|
|
|
return getObjectMapper().readValue(input, klass);
|
|
|
|
|
return getObjectMapper().readValue(notEmpty(input, "input"), klass);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**input의 내용을 파싱하여 주어진 클래스의 객체로 변환한다.
|
|
|
|
|
* @param <T> 클래스 유형
|
|
|
|
|
* @param input JSON input
|
|
|
|
|
* @param typeRef TypeReference
|
|
|
|
|
* @return input을 파싱하여 변환한 객체
|
|
|
|
|
*/
|
|
|
|
|
public <T> T parse(InputStream input, TypeReference<T> typeRef) {
|
|
|
|
|
try {
|
|
|
|
|
return getObjectMapper().readValue(input, typeRef);
|
|
|
|
|
return getObjectMapper().readValue(notEmpty(input, "input"), typeRef);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
throw runtimeException(e);
|
|
|
|
|
}
|
|
|
|
|
|