protected Object deserialize(Object root) throws ResourceException {

    Object result = null;

    if (root != null) {

      if (String.class.isAssignableFrom(root.getClass())) {
        try {
          result = getRequest().getEntity().getText();
        } catch (IOException e) {
          throw new ResourceException(
              Status.SERVER_ERROR_INTERNAL, "Cannot get the representation!", e);
        }
      }

      XStreamRepresentation representation = createRepresentation(getRequest().getEntity());

      if (representation != null) {
        try {
          result = representation.getPayload(root);
        } catch (XStreamException e) {
          logger.warn(
              "Invalid XML, unable to parse using XStream {}",
              (delegate == null ? "" : delegate.getClass()),
              e);

          throw new ResourceException(
              Status.CLIENT_ERROR_BAD_REQUEST, "Invalid XML, unable to parse using XStream", e);
        }
      }
    }
    return result;
  }