23b02d86677c24b8e4d2afe60bd9617c36442f7f
[facebook-utils] / src / main / java / de / juplo / facebook / GraphApiExceptionJackson2Serializer.java
1 package de.juplo.facebook;
2
3 import java.io.IOException;
4 import java.util.Map.Entry;
5
6 import com.fasterxml.jackson.core.JsonGenerator;
7 import com.fasterxml.jackson.core.JsonProcessingException;
8 import com.fasterxml.jackson.databind.SerializerProvider;
9 import com.fasterxml.jackson.databind.ser.std.StdSerializer;
10
11 /**
12  * @author Brian Clozel
13  *
14  */
15 public class GraphApiExceptionJackson2Serializer extends StdSerializer<GraphApiException> {
16
17     public GraphApiExceptionJackson2Serializer() {
18         super(GraphApiException.class);
19     }
20
21         @Override
22         public void serialize(GraphApiException value, JsonGenerator jgen, SerializerProvider provider) throws IOException,
23                         JsonProcessingException {
24         jgen.writeStartObject();
25                 jgen.writeStringField("error", value.getOAuth2ErrorCode());
26                 jgen.writeStringField("error_description", value.getMessage());
27                 if (value.getAdditionalInformation()!=null) {
28                         for (Entry<String, String> entry : value.getAdditionalInformation().entrySet()) {
29                                 String key = entry.getKey();
30                                 String add = entry.getValue();
31                                 jgen.writeStringField(key, add);                                
32                         }
33                 }
34         jgen.writeEndObject();
35         }
36
37 }