Как видно из заголовка, по какой-то причине я не могу получить дополнительную информацию для возврата
CustomOauthException. java
@JsonSerialize(using = CustomOauthExceptionSerializer.class)
public class CustomOauthException extends OAuth2Exception {
private static final long serialVersionUID = 4707824934161702832L;
public CustomOauthException(String msg) {
super(msg);
}
}
CustomOauthExceptionSerializer. java
Здесь value.getAdditionalInformation()
всегда равно нулю
public class CustomOauthExceptionSerializer extends StdSerializer<CustomOauthException> {
private static final long serialVersionUID = -4580017693074650272L;
private Logger log = LoggerFactory.getLogger(UserService.class);
public CustomOauthExceptionSerializer() {
super(CustomOauthException.class);
}
@Override
public void serialize(CustomOauthException value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeNumberField("code", value.getHttpErrorCode());
jsonGenerator.writeBooleanField("status", false);
jsonGenerator.writeObjectField("data", null);
jsonGenerator.writeObjectField("errors", Arrays.asList(value.getOAuth2ErrorCode(),value.getMessage()));
log.info("before if");
if (value.getAdditionalInformation() != null) {
for (Map.Entry<String, String> entry : value.getAdditionalInformation().entrySet()) {
String key = entry.getKey();
String add = entry.getValue();
log.info("this are the fields " + key + ":" + add);
jsonGenerator.writeObjectField(key, add);
}
}
jsonGenerator.writeEndObject();
}
}
CustomWebResponseExceptionTranslator. java
@Component("customWebResponseExceptionTranslator")
public class CustomWebResponseExceptionTranslator implements WebResponseExceptionTranslator<OAuth2Exception> {
@Override
public ResponseEntity<OAuth2Exception> translate(Exception e) throws Exception {
OAuth2Exception oAuth2Exception = (OAuth2Exception) e;
return ResponseEntity
.status(oAuth2Exception.getHttpErrorCode())
.body(new CustomOauthException(oAuth2Exception.getMessage()));
}
}
AuthorizationServerConfig. java
@Autowired
private CustomWebResponseExceptionTranslator customWebResponseExceptionTranslator;
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
...
endpoints.exceptionTranslator(customWebResponseExceptionTranslator);
}
и я выкидываю исключение таким образом
CustomOauthException ex = new CustomOauthException("something");
ex.addAdditionalInformation("someKey", "some value");
throw ex;
и в консоли я получаю это:
но в почтальоне я получаю это:
Есть идеи, почему ?
спасибо перед рукой ...