View Javadoc
1   package org.kuali.common.http.json;
2   
3   import java.io.IOException;
4   
5   import com.fasterxml.jackson.core.JsonGenerator;
6   import com.fasterxml.jackson.core.JsonProcessingException;
7   import com.fasterxml.jackson.databind.JsonSerializer;
8   import com.fasterxml.jackson.databind.SerializerProvider;
9   import com.google.common.base.Optional;
10  
11  public class IOExceptionSerializer extends JsonSerializer<Optional<IOException>> {
12  
13  	private static final String MESSAGE = "message";
14  
15  	@Override
16  	public void serialize(Optional<IOException> exception, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
17  		if (exception.isPresent()) {
18  			jgen.writeStartObject();
19  			jgen.writeStringField(MESSAGE, exception.get().getMessage());
20  			jgen.writeEndObject();
21  		} else {
22  			provider.defaultSerializeNull(jgen);
23  		}
24  	}
25  
26  }