protected ResultSerializer getResultSerializer(final MediaType mediaType) {

    final ResultSerializer serializer = getResultSerializer();
    final JSON jsonParser = new JSON();

    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 jsonParser.parse(new JSON.StringSource(serializer.serialize(result).toString()));
        }

        @Override
        public Object serializeError(ResultStatus error) {
          return jsonParser.parse(new JSON.StringSource(serializer.serializeError(error).toString()));
        }
      };
    }
    else if (mediaType.equals(MEDIA_TYPE_TEXT_CSV_TYPE)) {
      return new CsvSerializer();
    }

    throw new IllegalArgumentException("The media type " + mediaType + " is not supported.");
  }
Get a serializer for the given media type.

@param mediaType  the media type

@return the result serializer
ambari-server/src/main/java/org/apache/ambari/server/api/services/BaseService.java