@Test @SuppressWarnings("unchecked") public void formatMethodResponseShouldFilterRightFieldsForEachResponse() { ObjectResponseClass responseClass = new ObjectResponseClass(); responseClass.list = ImmutableList.of(new ObjectResponseClass.Foo("id", "name")); Property idProperty = () -> "id"; Property nameProperty = () -> "name"; List<InvocationResponse> response = testee.formatMethodResponse( Flux.just(JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) .methodCallId(MethodCallId.of("#1")) .properties(ImmutableSet.of(idProperty, nameProperty)) .response(responseClass) .build(), JmapResponse .builder() .responseName(Method.Response.name("unknownMethod")) .methodCallId(MethodCallId.of("#1")) .properties(ImmutableSet.of(idProperty)) .response(responseClass) .build())) .collectList() .block(); assertThat(response).hasSize(2) .extracting(x -> x.getResults().get("list").elements().next()) .extracting( x -> x.get("id").asText(), x -> Optional.ofNullable(x.get("name")).map(JsonNode::asText).orElse(null)) .containsExactly(tuple("id", "name"), tuple("id", null)); }
@Override public Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses) { return jmapResponses.map(jmapResponse -> { ObjectMapper objectMapper = newConfiguredObjectMapper(jmapResponse); return new InvocationResponse( jmapResponse.getResponseName(), objectMapper.valueToTree(jmapResponse.getResponse()), jmapResponse.getMethodCallId()); }); }
JmapResponseWriterImpl implements JmapResponseWriter { @Override public Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses) { return jmapResponses.map(jmapResponse -> { ObjectMapper objectMapper = newConfiguredObjectMapper(jmapResponse); return new InvocationResponse( jmapResponse.getResponseName(), objectMapper.valueToTree(jmapResponse.getResponse()), jmapResponse.getMethodCallId()); }); } }
JmapResponseWriterImpl implements JmapResponseWriter { @Override public Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses) { return jmapResponses.map(jmapResponse -> { ObjectMapper objectMapper = newConfiguredObjectMapper(jmapResponse); return new InvocationResponse( jmapResponse.getResponseName(), objectMapper.valueToTree(jmapResponse.getResponse()), jmapResponse.getMethodCallId()); }); } @Inject  JmapResponseWriterImpl(ObjectMapperFactory objectMapperFactory); }
JmapResponseWriterImpl implements JmapResponseWriter { @Override public Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses) { return jmapResponses.map(jmapResponse -> { ObjectMapper objectMapper = newConfiguredObjectMapper(jmapResponse); return new InvocationResponse( jmapResponse.getResponseName(), objectMapper.valueToTree(jmapResponse.getResponse()), jmapResponse.getMethodCallId()); }); } @Inject  JmapResponseWriterImpl(ObjectMapperFactory objectMapperFactory); @Override Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses); }
JmapResponseWriterImpl implements JmapResponseWriter { @Override public Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses) { return jmapResponses.map(jmapResponse -> { ObjectMapper objectMapper = newConfiguredObjectMapper(jmapResponse); return new InvocationResponse( jmapResponse.getResponseName(), objectMapper.valueToTree(jmapResponse.getResponse()), jmapResponse.getMethodCallId()); }); } @Inject  JmapResponseWriterImpl(ObjectMapperFactory objectMapperFactory); @Override Flux<InvocationResponse> formatMethodResponse(Flux<JmapResponse> jmapResponses); static final String PROPERTIES_FILTER; }