Package br.com.caelum.vraptor.deserialization

Examples of br.com.caelum.vraptor.deserialization.Deserializer


    if (!supported.isEmpty() && !supported.contains(contentType)) {
      unsupported("Request with media type [%s]. Expecting one of %s.", status, contentType, supported);
      return;
    }

    Deserializer deserializer = deserializers.deserializerFor(contentType, container);
    if (deserializer == null) {
      unsupported("Unable to handle media type [%s]: no deserializer found.", status, contentType);
      return;
    }

    Object[] deserialized = deserializer.deserialize(request.getInputStream(), method);
    logger.debug("Deserialized parameters for {} are {} ", method, deserialized);

    for (int i = 0; i < deserialized.length; i++) {
      if (deserialized[i] != null) {
        methodInfo.setParameter(i, deserialized[i]);
View Full Code Here


          contentType, supported));
      return;
    }

    try {
      Deserializer deserializer = deserializers.deserializerFor(contentType, container);
      if (deserializer == null) {
        unsupported(String.format("Unable to handle media type [%s]: no deserializer found.", contentType));
        return;
      }

      Object[] deserialized = deserializer.deserialize(request.getInputStream(), method);
      Object[] parameters = methodInfo.getParameters();

      for (int i = 0; i < deserialized.length; i++) {
        if (deserialized[i] != null) {
          parameters[i] = deserialized[i];
View Full Code Here

          contentType, supported));
      return;
    }

    try {
      Deserializer deserializer = deserializers.deserializerFor(contentType, container);
      if (deserializer == null) {
        unsupported(String.format("Unable to handle media type [%s]: no deserializer found.", contentType));
        return;
      }

      Object[] deserialized = deserializer.deserialize(request.getInputStream(), method);
      Object[] parameters = methodInfo.getParameters();
     
      if(logger.isDebugEnabled()) {
        logger.debug("Deserialized parameters for {} are {} ", method, Arrays.asList(deserialized));
      }
View Full Code Here

          contentType, supported));
      return;
    }

    try {
      Deserializer deserializer = deserializers.deserializerFor(contentType, container);
      if (deserializer == null) {
        unsupported(String.format("Unable to handle media type [%s]: no deserializer found.", contentType));
        return;
      }

      Object[] deserialized = deserializer.deserialize(request.getInputStream(), method);
      Object[] parameters = methodInfo.getParameters();

      logger.debug("Deserialized parameters for {} are {} ", method, deserialized);

      // TODO: a new array should be created and then a call to setParameters
View Full Code Here

  @Test
  public void willSetMethodParametersWithDeserializationAndContinueStackAfterDeserialization() {
    when(request.getContentType()).thenReturn("application/xml");

    final Deserializer deserializer = mock(Deserializer.class);
    methodInfo.setParameters(new Object[2]);
    when(deserializer.deserialize(null, consumeXml)).thenReturn(new Object[] {"abc", "def"});

    when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer);

    interceptor.intercept(stack, consumeXml, null);
View Full Code Here

  @Test
  public void willSetMethodParametersWithDeserializationEvenIfTheContentTypeHasCharsetDeclaration() {
    when(request.getContentType()).thenReturn("application/xml; charset=UTF-8");

    final Deserializer deserializer = mock(Deserializer.class);
    methodInfo.setParameters(new Object[2]);
    when(deserializer.deserialize(null, consumeXml)).thenReturn(new Object[] {"abc", "def"});

    when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer);

    interceptor.intercept(stack, consumeXml, null);
View Full Code Here

    when(request.getContentType()).thenReturn("application/xml");

    methodInfo.setParameters(new Object[2]);
    final DefaultResourceMethod consumesAnything = new DefaultResourceMethod(null, DummyResource.class.getDeclaredMethod("consumesAnything"));

    final Deserializer deserializer = mock(Deserializer.class);
    when(deserializer.deserialize(null, consumesAnything)).thenReturn(new Object[] {"abc", "def"});

    when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer);
    interceptor.intercept(stack, consumesAnything, null);

    assertEquals(methodInfo.getParameters()[0], "abc");
View Full Code Here

  @Test
  public void willSetOnlyNonNullParameters() throws Exception {
    when(request.getContentType()).thenReturn("application/xml");

    final Deserializer deserializer = mock(Deserializer.class);
    methodInfo.setParameters(new Object[] {"original1", "original2"});
    when(deserializer.deserialize(null, consumeXml)).thenReturn(new Object[] {null, "deserialized"});

    when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer);
    interceptor.intercept(stack, consumeXml, null);

    assertEquals(methodInfo.getParameters()[0], "original1");
View Full Code Here

  @Test(expected = InterceptionException.class)
  public void shouldThrowInterceptionExceptionIfAnIOExceptionOccurs() throws Exception {
    when(request.getInputStream()).thenThrow(new IOException());
    when(request.getContentType()).thenReturn("application/xml");
   
    final Deserializer deserializer = mock(Deserializer.class);
    when(deserializers.deserializerFor("application/xml", container)).thenReturn(deserializer);
    interceptor.intercept(stack, consumeXml, null);
  }
View Full Code Here

          contentType, supported));
      return;
    }

    try {
      Deserializer deserializer = deserializers.deserializerFor(contentType, container);
      if (deserializer == null) {
        unsupported(String.format("Unable to handle media type [%s]: no deserializer found.", contentType));
        return;
      }

      Object[] deserialized = deserializer.deserialize(request.getInputStream(), method);
      Object[] parameters = methodInfo.getParameters();

      for (int i = 0; i < deserialized.length; i++) {
        if (deserialized[i] != null) {
          parameters[i] = deserialized[i];
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.deserialization.Deserializer

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.