Search in sources :

Example 1 with MyJacksonView1

use of org.springframework.http.codec.json.JacksonViewBean.MyJacksonView1 in project spring-framework by spring-projects.

the class Jackson2JsonDecoderTests method fieldLevelJsonView.

@Test
public void fieldLevelJsonView() {
    Flux<DataBuffer> input = Flux.from(stringBuffer("{\"withView1\" : \"with\", \"withView2\" : \"with\", \"withoutView\" : \"without\"}"));
    ResolvableType elementType = ResolvableType.forClass(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) StepVerifier(reactor.test.StepVerifier) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DecodingException(org.springframework.core.codec.DecodingException) JSON_VIEW_HINT(org.springframework.http.codec.json.Jackson2CodecSupport.JSON_VIEW_HINT) APPLICATION_XML(org.springframework.http.MediaType.APPLICATION_XML) CodecException(org.springframework.core.codec.CodecException) StdDeserializer(com.fasterxml.jackson.databind.deser.std.StdDeserializer) MimeType(org.springframework.util.MimeType) APPLICATION_NDJSON(org.springframework.http.MediaType.APPLICATION_NDJSON) BigDecimal(java.math.BigDecimal) MyJacksonView1(org.springframework.http.codec.json.JacksonViewBean.MyJacksonView1) Charset(java.nio.charset.Charset) Map(java.util.Map) MyJacksonView3(org.springframework.http.codec.json.JacksonViewBean.MyJacksonView3) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) JsonNode(com.fasterxml.jackson.databind.JsonNode) ResolvableType(org.springframework.core.ResolvableType) APPLICATION_JSON(org.springframework.http.MediaType.APPLICATION_JSON) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pojo(org.springframework.web.testfixture.xml.Pojo) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) APPLICATION_STREAM_JSON(org.springframework.http.MediaType.APPLICATION_STREAM_JSON) Flux(reactor.core.publisher.Flux) List(java.util.List) AbstractDecoderTests(org.springframework.core.testfixture.codec.AbstractDecoderTests) Collections(java.util.Collections) JsonDeserialize(com.fasterxml.jackson.databind.annotation.JsonDeserialize) ResolvableType(org.springframework.core.ResolvableType) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JsonDeserialize (com.fasterxml.jackson.databind.annotation.JsonDeserialize)1 StdDeserializer (com.fasterxml.jackson.databind.deser.std.StdDeserializer)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 ResolvableType (org.springframework.core.ResolvableType)1 CodecException (org.springframework.core.codec.CodecException)1