diff --git a/src/main/java/cokr/xit/foundation/data/JSON.java b/src/main/java/cokr/xit/foundation/data/JSON.java index 75970b0..14cb146 100644 --- a/src/main/java/cokr/xit/foundation/data/JSON.java +++ b/src/main/java/cokr/xit/foundation/data/JSON.java @@ -73,17 +73,30 @@ public class JSON extends AbstractComponent { */ public T parse(String json, Class 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 클래스 유형 + * @param json JSON 문자열 + * @param typeRef TypeReference + * @return 문자열을 파싱하여 변환한 객체 + */ public T parse(String json, TypeReference 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 parse(InputStream input, Class klass) { try { - return getObjectMapper().readValue(input, klass); + return getObjectMapper().readValue(notEmpty(input, "input"), klass); } catch (Exception e) { throw runtimeException(e); } } + /**input의 내용을 파싱하여 주어진 클래스의 객체로 변환한다. + * @param 클래스 유형 + * @param input JSON input + * @param typeRef TypeReference + * @return input을 파싱하여 변환한 객체 + */ public T parse(InputStream input, TypeReference typeRef) { try { - return getObjectMapper().readValue(input, typeRef); + return getObjectMapper().readValue(notEmpty(input, "input"), typeRef); } catch (Exception e) { throw runtimeException(e); } diff --git a/src/main/java/cokr/xit/foundation/data/XML.java b/src/main/java/cokr/xit/foundation/data/XML.java index 1ca624c..f5b7d70 100644 --- a/src/main/java/cokr/xit/foundation/data/XML.java +++ b/src/main/java/cokr/xit/foundation/data/XML.java @@ -58,15 +58,28 @@ public class XML extends AbstractComponent { try { return getXmlMapper().readValue(xml, klass); } catch (Exception e) { - throw runtimeException(e); + throw parsingException(xml, e); } } + private static RuntimeException parsingException(String xml, Exception e) { + Throwable cause = rootCause(e); + String msg = cause.getLocalizedMessage(); + log(XML.class).debug("{} while parsing the following string:\n{}", msg, xml); + return runtimeException(cause); + } + + /**XML 문자열을 파싱하여 주어진 클래스의 객체로 변환한다. + * @param 클래스 유형 + * @param xml XML 문자열 + * @param typeRef TypeReference + * @return 문자열을 파싱하여 변환한 객체 + */ public T parse(String xml, TypeReference typeRef) { try { return getXmlMapper().readValue(xml, typeRef); } catch (Exception e) { - throw runtimeException(e); + throw parsingException(xml, e); } } @@ -84,6 +97,12 @@ public class XML extends AbstractComponent { } } + /**input의 내용을 파싱하여 주어진 클래스의 객체로 변환한다. + * @param 클래스 유형 + * @param input XML input + * @param typeRef TypeReference + * @return input을 파싱하여 변환한 객체 + */ public T parse(InputStream input, TypeReference typeRef) { try { return getXmlMapper().readValue(input, typeRef);