parsingException(..) 추가

master
mjkhan21 8 months ago
parent 61b2d3c56f
commit 2c1cde7f7d

@ -73,17 +73,30 @@ public class JSON extends AbstractComponent {
*/ */
public <T> T parse(String json, Class<T> klass) { public <T> T parse(String json, Class<T> klass) {
try { try {
return getObjectMapper().readValue(json, klass); return getObjectMapper().readValue(notEmpty(json, "json"), klass);
} catch (Exception e) { } 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) { public <T> T parse(String json, TypeReference<T> typeRef) {
try { try {
return getObjectMapper().readValue(json, typeRef); return getObjectMapper().readValue(notEmpty(json, "json"), typeRef);
} catch (Exception e) { } 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) { public <T> T parse(InputStream input, Class<T> klass) {
try { try {
return getObjectMapper().readValue(input, klass); return getObjectMapper().readValue(notEmpty(input, "input"), klass);
} catch (Exception e) { } catch (Exception e) {
throw runtimeException(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) { public <T> T parse(InputStream input, TypeReference<T> typeRef) {
try { try {
return getObjectMapper().readValue(input, typeRef); return getObjectMapper().readValue(notEmpty(input, "input"), typeRef);
} catch (Exception e) { } catch (Exception e) {
throw runtimeException(e); throw runtimeException(e);
} }

@ -58,15 +58,28 @@ public class XML extends AbstractComponent {
try { try {
return getXmlMapper().readValue(xml, klass); return getXmlMapper().readValue(xml, klass);
} catch (Exception e) { } 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 <T>
* @param xml XML
* @param typeRef TypeReference
* @return
*/
public <T> T parse(String xml, TypeReference<T> typeRef) { public <T> T parse(String xml, TypeReference<T> typeRef) {
try { try {
return getXmlMapper().readValue(xml, typeRef); return getXmlMapper().readValue(xml, typeRef);
} catch (Exception e) { } catch (Exception e) {
throw runtimeException(e); throw parsingException(xml, e);
} }
} }
@ -84,6 +97,12 @@ public class XML extends AbstractComponent {
} }
} }
/**input .
* @param <T>
* @param input XML input
* @param typeRef TypeReference
* @return input
*/
public <T> T parse(InputStream input, TypeReference<T> typeRef) { public <T> T parse(InputStream input, TypeReference<T> typeRef) {
try { try {
return getXmlMapper().readValue(input, typeRef); return getXmlMapper().readValue(input, typeRef);

Loading…
Cancel
Save