Package org.apache.ambari.server.api.services.serializers

Examples of org.apache.ambari.server.api.services.serializers.ResultSerializer


      }
    } catch (BodyParseException e) {
      result =  new ResultImpl(new ResultStatus(ResultStatus.STATUS.BAD_REQUEST, e.getMessage()));
    }

    ResultSerializer serializer = mediaType == null ? getResultSerializer() : getResultSerializer(mediaType);

    Response.ResponseBuilder builder = Response.status(result.getStatus().getStatusCode()).entity(
        serializer.serialize(result));

    if (mediaType != null) {
      builder.type(mediaType);
    }
View Full Code Here


   *
   * @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.");
  }
View Full Code Here

    Resource.Type type = new Resource.Type("subResource");

    // get resource
    ViewSubResourceService service = new ViewSubResourceService(type, viewInstanceEntity);

    ResultSerializer serializer = service.getResultSerializer(MediaType.TEXT_PLAIN_TYPE);

    Object o = serializer.serialize(result);

    String expected = "{\n" +
        "  \"href\" : \"this is an href\",\n" +
        "  \"prop2\" : \"value2\",\n" +
        "  \"prop1\" : \"value1\",\n" +
View Full Code Here

    Resource.Type type = new Resource.Type("subResource");

    // get resource
    ViewSubResourceService service = new ViewSubResourceService(type, viewInstanceEntity);

    ResultSerializer serializer = service.getResultSerializer(MediaType.APPLICATION_JSON_TYPE);

    Object o = serializer.serialize(result);

    assertTrue(o instanceof Map);
    Map map = (Map) o;
    assertEquals(4, map.size());
    assertEquals("value1", map.get("prop1"));
View Full Code Here

TOP

Related Classes of org.apache.ambari.server.api.services.serializers.ResultSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.