1
2
3
4
5
6
7
8
9
10
11
12
13 package org.springframework.security.oauth2.common.exceptions;
14
15 import java.io.IOException;
16 import java.util.Map.Entry;
17
18 import com.fasterxml.jackson.core.JsonGenerator;
19 import com.fasterxml.jackson.core.JsonProcessingException;
20 import com.fasterxml.jackson.databind.SerializerProvider;
21 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
22
23
24
25
26
27 public class OAuth2ExceptionJackson2Serializer extends StdSerializer<OAuth2Exception> {
28
29 public OAuth2ExceptionJackson2Serializer() {
30 super(OAuth2Exception.class);
31 }
32
33 @Override
34 public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
35 JsonProcessingException {
36 jgen.writeStartObject();
37 jgen.writeStringField("error", value.getOAuth2ErrorCode());
38 jgen.writeStringField("error_description", value.getMessage());
39 if (value.getAdditionalInformation()!=null) {
40 for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) {
41 String key = entry.getKey();
42 String add = entry.getValue();
43 jgen.writeStringField(key, add);
44 }
45 }
46 jgen.writeEndObject();
47 }
48
49 }