mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
fix: Jackson compatibility issue preventing 5.x server from scheduling 4.x worker
This commit is contained in:
parent
9dbd470c5a
commit
d1d0407046
@ -8,6 +8,11 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
|
||||
/**
|
||||
* The result object returned by the request
|
||||
* <p>
|
||||
* 低版本由于 Jackson 序列化配置问题,导致无法在此对象上新增任何字段了,否则会报错 com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "code" (class tech.powerjob.common.response.ObjectResultDTO), not marked as ignorable (3 known properties: "data", "success", "message"])
|
||||
* at [Source: (String)"{"success":true,"code":null,"data":2,"message":null}"; line: 1, column: 28] (through reference chain: tech.powerjob.common.response.ObjectResultDTO["code"])
|
||||
* <p>
|
||||
* 短期内所有的新增字段需求,都通过新对象继承实现
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2020/3/30
|
||||
@ -17,10 +22,9 @@ import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
@ToString
|
||||
public class ResultDTO<T> implements PowerSerializable {
|
||||
|
||||
private boolean success;
|
||||
private String code;
|
||||
private T data;
|
||||
private String message;
|
||||
protected boolean success;
|
||||
protected T data;
|
||||
protected String message;
|
||||
|
||||
public static <T> ResultDTO<T> success(T data) {
|
||||
ResultDTO<T> r = new ResultDTO<>();
|
||||
|
@ -10,6 +10,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import tech.powerjob.common.exception.PowerJobException;
|
||||
import tech.powerjob.common.response.ResultDTO;
|
||||
import tech.powerjob.server.web.response.WebResultDTO;
|
||||
|
||||
/**
|
||||
* 统一处理 web 层异常信息
|
||||
@ -23,9 +24,9 @@ public class ControllerExceptionHandler {
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResultDTO<Void> exceptionHandler(Exception e) {
|
||||
public WebResultDTO<Void> exceptionHandler(Exception e) {
|
||||
|
||||
ResultDTO<Void> ret = ResultDTO.failed(ExceptionUtils.getMessage(e));
|
||||
WebResultDTO<Void> ret = new WebResultDTO<>(ResultDTO.failed(ExceptionUtils.getMessage(e)));
|
||||
|
||||
// 不是所有异常都需要打印完整堆栈,后续可以定义内部的Exception,便于判断
|
||||
if (e instanceof PowerJobException) {
|
||||
|
@ -0,0 +1,27 @@
|
||||
package tech.powerjob.server.web.response;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import tech.powerjob.common.response.ResultDTO;
|
||||
|
||||
/**
|
||||
* WEB 请求结果
|
||||
*
|
||||
* @author tjq
|
||||
* @since 2024/2/18
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class WebResultDTO<T> extends ResultDTO<T> {
|
||||
|
||||
private String code;
|
||||
|
||||
public WebResultDTO() {
|
||||
}
|
||||
|
||||
public WebResultDTO(ResultDTO<T> res) {
|
||||
this.success = res.isSuccess();
|
||||
this.data = res.getData();
|
||||
this.message = res.getMessage();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user