refactor: JSON serialize exception (#2222)

pull/2223/head
guqing 2022-07-07 17:32:14 +08:00 committed by GitHub
parent 2afe19f1b9
commit 73d43cae64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -0,0 +1,30 @@
package run.halo.app.infra.utils;
/**
* {@link JsonParseException} thrown when source JSON is invalid.
*
* @author guqing
* @since 2.0.0
*/
public class JsonParseException extends RuntimeException {
public JsonParseException() {
super();
}
public JsonParseException(String message) {
super(message);
}
public JsonParseException(String message, Throwable cause) {
super(message, cause);
}
public JsonParseException(Throwable cause) {
super(cause);
}
protected JsonParseException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@ -77,7 +77,7 @@ public class JsonUtils {
try {
return DEFAULT_JSON_MAPPER.writeValueAsString(source);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
throw new JsonParseException(e);
}
}
@ -93,7 +93,7 @@ public class JsonUtils {
try {
return DEFAULT_JSON_MAPPER.readValue(json, toValueType);
} catch (Exception e) {
throw new RuntimeException(e);
throw new JsonParseException(e);
}
}
}