com.healthy.security.server.HealthyAuth2ExceptionSerializer Maven / Gradle / Ivy
package com.healthy.security.server;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.healthy.security.server.exception.HealthyAuth2Exception;
import lombok.SneakyThrows;
/**
* OAuth2 异常格式化
*
* @author xiaomingzhang
*/
public class HealthyAuth2ExceptionSerializer extends StdSerializer {
public HealthyAuth2ExceptionSerializer() {
super(HealthyAuth2Exception.class);
}
@Override
@SneakyThrows
public void serialize(HealthyAuth2Exception value, JsonGenerator gen, SerializerProvider provider) {
gen.writeStartObject();
gen.writeObjectField("success", false);
gen.writeStringField("msg", value.getMessage());
gen.writeStringField("data", value.getErrorCode());
// 资源服务器会读取这个字段
gen.writeStringField("error", value.getMessage());
gen.writeEndObject();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy