Search in sources :

Example 1 with MyJacksonView1

use of cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView1 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);
}
Also used : Arrays(java.util.Arrays) MyJacksonView1(cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView1) StepVerifier(reactor.test.StepVerifier) MyJacksonView3(cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView3) Pojo(cn.taketoday.http.codec.Pojo) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CodecException(cn.taketoday.core.codec.CodecException) APPLICATION_JSON(cn.taketoday.http.MediaType.APPLICATION_JSON) StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) APPLICATION_NDJSON(cn.taketoday.http.MediaType.APPLICATION_NDJSON) BigDecimal(java.math.BigDecimal) Charset(java.nio.charset.Charset) APPLICATION_STREAM_JSON(cn.taketoday.http.MediaType.APPLICATION_STREAM_JSON) Map(java.util.Map) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(cn.taketoday.core.TypeReference) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ResolvableType(cn.taketoday.core.ResolvableType) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) AbstractDecoderTests(cn.taketoday.core.codec.AbstractDecoderTests) MediaType(cn.taketoday.http.MediaType) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) APPLICATION_XML(cn.taketoday.http.MediaType.APPLICATION_XML) JSON_VIEW_HINT(cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT) DecodingException(cn.taketoday.core.codec.DecodingException) MimeType(cn.taketoday.util.MimeType) ResolvableType(cn.taketoday.core.ResolvableType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with MyJacksonView1

use of cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView1 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);
}
Also used : Arrays(java.util.Arrays) MyJacksonView1(cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView1) StepVerifier(reactor.test.StepVerifier) MyJacksonView3(cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView3) Pojo(cn.taketoday.http.codec.Pojo) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CodecException(cn.taketoday.core.codec.CodecException) APPLICATION_JSON(cn.taketoday.http.MediaType.APPLICATION_JSON) StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) APPLICATION_NDJSON(cn.taketoday.http.MediaType.APPLICATION_NDJSON) BigDecimal(java.math.BigDecimal) Charset(java.nio.charset.Charset) APPLICATION_STREAM_JSON(cn.taketoday.http.MediaType.APPLICATION_STREAM_JSON) Map(java.util.Map) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(cn.taketoday.core.TypeReference) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ResolvableType(cn.taketoday.core.ResolvableType) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) AbstractDecoderTests(cn.taketoday.core.codec.AbstractDecoderTests) MediaType(cn.taketoday.http.MediaType) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) Collections(java.util.Collections) APPLICATION_XML(cn.taketoday.http.MediaType.APPLICATION_XML) JSON_VIEW_HINT(cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT) DecodingException(cn.taketoday.core.codec.DecodingException) MimeType(cn.taketoday.util.MimeType) ResolvableType(cn.taketoday.core.ResolvableType) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

ResolvableType (cn.taketoday.core.ResolvableType)2 TypeReference (cn.taketoday.core.TypeReference)2 AbstractDecoderTests (cn.taketoday.core.codec.AbstractDecoderTests)2 CodecException (cn.taketoday.core.codec.CodecException)2 DecodingException (cn.taketoday.core.codec.DecodingException)2 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)2 MediaType (cn.taketoday.http.MediaType)2 APPLICATION_JSON (cn.taketoday.http.MediaType.APPLICATION_JSON)2 APPLICATION_NDJSON (cn.taketoday.http.MediaType.APPLICATION_NDJSON)2 APPLICATION_STREAM_JSON (cn.taketoday.http.MediaType.APPLICATION_STREAM_JSON)2 APPLICATION_XML (cn.taketoday.http.MediaType.APPLICATION_XML)2 Pojo (cn.taketoday.http.codec.Pojo)2 JSON_VIEW_HINT (cn.taketoday.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT)2 MyJacksonView1 (cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView1)2 MyJacksonView3 (cn.taketoday.http.codec.json.JacksonViewBean.MyJacksonView3)2 MimeType (cn.taketoday.util.MimeType)2 JsonParser (com.fasterxml.jackson.core.JsonParser)2 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2