@Override
  public Object readFrom(
      Class<Object> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders,
      InputStream entityStream)
      throws IOException, WebApplicationException {
    final String entityString = readFromAsString(entityStream, mediaType);
    if (entityString.isEmpty()) {
      throw new NoContentException(LocalizationMessages.ERROR_READING_ENTITY_MISSING());
    }
    final PrimitiveTypes primitiveType = PrimitiveTypes.forType(type);
    if (primitiveType != null) {
      return primitiveType.convert(entityString);
    }

    final Constructor constructor =
        AccessController.doPrivileged(ReflectionHelper.getStringConstructorPA(type));
    if (constructor != null) {
      try {
        return type.cast(constructor.newInstance(entityString));
      } catch (Exception e) {
        throw new MessageBodyProcessingException(
            LocalizationMessages.ERROR_ENTITY_PROVIDER_BASICTYPES_CONSTRUCTOR(type));
      }
    }

    if (AtomicInteger.class.isAssignableFrom(type)) {
      return new AtomicInteger((Integer) PrimitiveTypes.INTEGER.convert(entityString));
    }

    if (AtomicLong.class.isAssignableFrom(type)) {
      return new AtomicLong((Long) PrimitiveTypes.LONG.convert(entityString));
    }

    throw new MessageBodyProcessingException(
        LocalizationMessages.ERROR_ENTITY_PROVIDER_BASICTYPES_UNKWNOWN(type));
  }
  @Override
  public final Object readFrom(
      Class<Object> type,
      Type genericType,
      Annotation annotations[],
      MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders,
      InputStream inputStream)
      throws IOException {

    try {
      final EntityInputStream entityStream = EntityInputStream.create(inputStream);
      if (entityStream.isEmpty()) {
        throw new NoContentException(LocalizationMessages.ERROR_READING_ENTITY_MISSING());
      }
      return readFrom(type, mediaType, getUnmarshaller(type, mediaType), entityStream);
    } catch (UnmarshalException ex) {
      throw new BadRequestException(ex);
    } catch (JAXBException ex) {
      throw new InternalServerErrorException(ex);
    }
  }