WorkspaceEntityProvider implements MessageBodyReader<WorkspaceDto>, MessageBodyWriter<WorkspaceDto> { @Override public WorkspaceDto readFrom( Class<WorkspaceDto> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { try { JsonNode wsNode = mapper.readTree(entityStream); JsonNode devfileNode = wsNode.path("devfile"); if (!devfileNode.isNull() && !devfileNode.isMissingNode()) { devfileParser.parseJson(devfileNode.toString()); } return DtoFactory.getInstance().createDtoFromJson(wsNode.toString(), WorkspaceDto.class); } catch (DevfileFormatException e) { throw new BadRequestException(e.getMessage()); } catch (IOException e) { throw new WebApplicationException(e.getMessage(), e); } } @Inject  WorkspaceEntityProvider(DevfileParser devfileParser); @Override boolean isReadable(
      Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override WorkspaceDto readFrom(
      Class<WorkspaceDto> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, String> httpHeaders,
      InputStream entityStream); @Override boolean isWriteable(
      Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType); @Override long getSize(
      WorkspaceDto workspaceDto,
      Class<?> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType); @Override void writeTo(
      WorkspaceDto workspaceDto,
      Class<?> type,
      Type genericType,
      Annotation[] annotations,
      MediaType mediaType,
      MultivaluedMap<String, Object> httpHeaders,
      OutputStream entityStream);  }
@Test public void shouldBuildDtoFromValidJson() throws Exception { when(devfileParser.parseJson(anyString())).thenReturn(new DevfileImpl()); WorkspaceDto actual = newDto(WorkspaceDto.class).withDevfile(newDto(DevfileDto.class)); workspaceEntityProvider.readFrom( WorkspaceDto.class, WorkspaceDto.class, null, MediaType.APPLICATION_JSON_TYPE, new MultivaluedHashMap<>(), new ByteArrayInputStream( DtoFactory.getInstance().toJson(actual).getBytes(StandardCharsets.UTF_8))); verify(devfileParser).parseJson(anyString()); }