*
* @return the result serializer
*/
protected ResultSerializer getResultSerializer(final MediaType mediaType) {
final ResultSerializer serializer = getResultSerializer();
if (mediaType.equals(MediaType.TEXT_PLAIN_TYPE)){
return new ResultSerializer() {
@Override
public Object serialize(Result result) {
return serializer.serialize(result).toString();
}
@Override
public Object serializeError(ResultStatus error) {
return serializer.serializeError(error).toString();
}
};
} else if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)){
return new ResultSerializer() {
@Override
public Object serialize(Result result) {
return JSON.parse(serializer.serialize(result).toString());
}
@Override
public Object serializeError(ResultStatus error) {
return JSON.parse(serializer.serializeError(error).toString());
}
};
}
throw new IllegalArgumentException("The media type " + mediaType + " is not supported.");
}