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 org.codehaus.jackson.JsonGenerator;
19 import org.codehaus.jackson.JsonProcessingException;
20 import org.codehaus.jackson.map.JsonSerializer;
21 import org.codehaus.jackson.map.SerializerProvider;
22
23
24
25
26
27 public class OAuth2ExceptionJackson1Serializer extends JsonSerializer<OAuth2Exception> {
28
29 @Override
30 public void serialize(OAuth2Exception value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
31 JsonProcessingException {
32 jgen.writeStartObject();
33 jgen.writeStringField("error", value.getOAuth2ErrorCode());
34 jgen.writeStringField("error_description", value.getMessage());
35 if (value.getAdditionalInformation()!=null) {
36 for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) {
37 String key = entry.getKey();
38 String add = entry.getValue();
39 jgen.writeStringField(key, add);
40 }
41 }
42 jgen.writeEndObject();
43 }
44
45 }