use of cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT in project today-framework by TAKETODAY.
the class Jackson2JsonDecoderTests method fieldLevelJsonView.
@Test
public void fieldLevelJsonView() {
Flux<DataBuffer> input = Flux.from(stringBuffer("{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"));
ResolvableType elementType = ResolvableType.fromClass(JacksonViewBean.class);
Map<String, Object> hints = Collections.singletonMap(JSON_VIEW_HINT, MyJacksonView1.class);
testDecode(input, elementType, step -> step.consumeNextWith(value -> {
JacksonViewBean bean = (JacksonViewBean) value;
assertThat(bean.getWithView1()).isEqualTo("with");
assertThat(bean.getWithView2()).isNull();
assertThat(bean.getWithoutView()).isNull();
}), null, hints);
}
use of cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT in project today-framework by TAKETODAY.
the class BodyExtractorsTests method toFluxWithHints.
@Test
public void toFluxWithHints() {
BodyExtractor<Flux<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(User.class);
this.hints.put(JSON_VIEW_HINT, SafeToDeserialize.class);
String text = "[{\"username\":\"foo\",\"password\":\"bar\"},{\"username\":\"bar\",\"password\":\"baz\"}]";
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.APPLICATION_JSON).body(body);
Flux<User> result = extractor.extract(request, this.context);
StepVerifier.create(result).consumeNextWith(user -> {
assertThat(user.getUsername()).isEqualTo("foo");
assertThat(user.getPassword()).isNull();
}).consumeNextWith(user -> {
assertThat(user.getUsername()).isEqualTo("bar");
assertThat(user.getPassword()).isNull();
}).expectComplete().verify();
}
use of cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT in project today-infrastructure by TAKETODAY.
the class Jackson2JsonDecoderTests method fieldLevelJsonView.
@Test
public void fieldLevelJsonView() {
Flux<DataBuffer> input = Flux.from(stringBuffer("{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"));
ResolvableType elementType = ResolvableType.fromClass(JacksonViewBean.class);
Map<String, Object> hints = Collections.singletonMap(JSON_VIEW_HINT, MyJacksonView1.class);
testDecode(input, elementType, step -> step.consumeNextWith(value -> {
JacksonViewBean bean = (JacksonViewBean) value;
assertThat(bean.getWithView1()).isEqualTo("with");
assertThat(bean.getWithView2()).isNull();
assertThat(bean.getWithoutView()).isNull();
}), null, hints);
}
use of cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT in project today-infrastructure by TAKETODAY.
the class BodyExtractorsTests method toFluxWithHints.
@Test
public void toFluxWithHints() {
BodyExtractor<Flux<User>, ReactiveHttpInputMessage> extractor = BodyExtractors.toFlux(User.class);
this.hints.put(JSON_VIEW_HINT, SafeToDeserialize.class);
String text = "[{\"username\":\"foo\",\"password\":\"bar\"},{\"username\":\"bar\",\"password\":\"baz\"}]";
byte[] bytes = text.getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(MediaType.APPLICATION_JSON).body(body);
Flux<User> result = extractor.extract(request, this.context);
StepVerifier.create(result).consumeNextWith(user -> {
assertThat(user.getUsername()).isEqualTo("foo");
assertThat(user.getPassword()).isNull();
}).consumeNextWith(user -> {
assertThat(user.getUsername()).isEqualTo("bar");
assertThat(user.getPassword()).isNull();
}).expectComplete().verify();
}
Aggregations