Search in sources :

Example 16 with SerializerProvider

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project api-core by ca-cwds.

the class CmsSystemCodeSerializerTest method serialize_Args$Short$JsonGenerator$SerializerProvider.

@Test
public void serialize_Args$Short$JsonGenerator$SerializerProvider() throws Exception {
    SystemCodeCache cache = null;
    CmsSystemCodeSerializer target = new CmsSystemCodeSerializer(cache);
    // given
    Short s = null;
    JsonGenerator jgen = mock(JsonGenerator.class);
    SerializerProvider sp = mock(SerializerProvider.class);
    // e.g. : given(mocked.called()).willReturn(1);
    // when
    target.serialize(s, jgen, sp);
// then
// e.g. : verify(mocked).called();
}
Also used : SystemCodeCache(gov.ca.cwds.rest.api.domain.cms.SystemCodeCache) TestSystemCodeCache(gov.ca.cwds.rest.validation.TestSystemCodeCache) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Test(org.junit.Test)

Example 17 with SerializerProvider

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project rpki-validator-3 by RIPE-NCC.

the class ApiConfig method customizeLinksRendering.

@Bean
public Jackson2ObjectMapperBuilderCustomizer customizeLinksRendering() {
    return (jacksonObjectMapperBuilder) -> {
        jacksonObjectMapperBuilder.serializerByType(Links.class, new JsonObjectSerializer<Links>() {

            @Override
            protected void serializeObject(Links value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
                for (Link link : value) {
                    jgen.writeStringField(link.getRel(), link.getHref());
                }
            }
        });
        jacksonObjectMapperBuilder.deserializerByType(Links.class, new JsonObjectDeserializer<Links>() {

            @Override
            protected Links deserializeObject(JsonParser jsonParser, DeserializationContext context, ObjectCodec codec, JsonNode tree) throws IOException {
                Iterator<Map.Entry<String, JsonNode>> iterator = tree.fields();
                List<Link> links = new ArrayList<>();
                while (iterator.hasNext()) {
                    Map.Entry<String, JsonNode> field = iterator.next();
                    links.add(new Link(field.getValue().asText(), field.getKey()));
                }
                return new Links(links);
            }
        });
    };
}
Also used : Jackson2ObjectMapperBuilderCustomizer(org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer) Arrays(java.util.Arrays) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) Links(org.springframework.hateoas.Links) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) ApiLogger(net.ripe.rpki.validator3.api.ApiLogger) ArrayList(java.util.ArrayList) Api(net.ripe.rpki.validator3.api.Api) InterceptorRegistry(org.springframework.web.servlet.config.annotation.InterceptorRegistry) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Link(org.springframework.hateoas.Link) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) JsonParser(com.fasterxml.jackson.core.JsonParser) Iterator(java.util.Iterator) MediaType(org.springframework.http.MediaType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) JsonObjectDeserializer(org.springframework.boot.jackson.JsonObjectDeserializer) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) JsonObjectSerializer(org.springframework.boot.jackson.JsonObjectSerializer) ContentNegotiationConfigurer(org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer) Bean(org.springframework.context.annotation.Bean) WebMvcConfigurer(org.springframework.web.servlet.config.annotation.WebMvcConfigurer) JsonObjectSerializer(org.springframework.boot.jackson.JsonObjectSerializer) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) JsonObjectDeserializer(org.springframework.boot.jackson.JsonObjectDeserializer) Links(org.springframework.hateoas.Links) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Map(java.util.Map) Link(org.springframework.hateoas.Link) JsonParser(com.fasterxml.jackson.core.JsonParser) Bean(org.springframework.context.annotation.Bean)

Example 18 with SerializerProvider

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.

the class ServletResponseResultWriter method getWriteBlobAsBase64Module.

private static SimpleModule getWriteBlobAsBase64Module() {
    JsonSerializer<Blob> dateSerializer = new JsonSerializer<Blob>() {

        @Override
        public void serialize(Blob value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            byte[] bytes = value.getBytes();
            jgen.writeBinary(bytes, 0, bytes.length);
        }
    };
    SimpleModule writeBlobAsBase64Module = new SimpleModule("writeBlobAsBase64Module", new Version(1, 0, 0, null, null, null));
    writeBlobAsBase64Module.addSerializer(Blob.class, dateSerializer);
    return writeBlobAsBase64Module;
}
Also used : Blob(com.google.appengine.api.datastore.Blob) Version(com.fasterxml.jackson.core.Version) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 19 with SerializerProvider

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.

the class ServletResponseResultWriter method getWriteDateAsStringModule.

private static SimpleModule getWriteDateAsStringModule() {
    JsonSerializer<Date> dateSerializer = new JsonSerializer<Date>() {

        @Override
        public void serialize(Date value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(new com.google.api.client.util.DateTime(value).toStringRfc3339());
        }
    };
    SimpleModule writeDateAsStringModule = new SimpleModule("writeDateAsStringModule", new Version(1, 0, 0, null, null, null));
    writeDateAsStringModule.addSerializer(Date.class, dateSerializer);
    return writeDateAsStringModule;
}
Also used : Version(com.fasterxml.jackson.core.Version) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) Date(java.util.Date) SimpleDate(com.google.api.server.spi.types.SimpleDate) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 20 with SerializerProvider

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider in project endpoints-java by cloudendpoints.

the class ServletResponseResultWriter method getWriteSimpleDateAsStringModule.

private static SimpleModule getWriteSimpleDateAsStringModule() {
    JsonSerializer<SimpleDate> simpleDateSerializer = new JsonSerializer<SimpleDate>() {

        @Override
        public void serialize(SimpleDate value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
            jgen.writeString(String.format("%04d-%02d-%02d", value.getYear(), value.getMonth(), value.getDay()));
        }
    };
    SimpleModule writeSimpleDateAsModule = new SimpleModule("writeSimpleDateAsModule", new Version(1, 0, 0, null, null, null));
    writeSimpleDateAsModule.addSerializer(SimpleDate.class, simpleDateSerializer);
    return writeSimpleDateAsModule;
}
Also used : Version(com.fasterxml.jackson.core.Version) SimpleDate(com.google.api.server.spi.types.SimpleDate) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) JsonSerializer(com.fasterxml.jackson.databind.JsonSerializer) SerializerProvider(com.fasterxml.jackson.databind.SerializerProvider) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Aggregations

SerializerProvider (com.fasterxml.jackson.databind.SerializerProvider)26 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)20 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)11 IOException (java.io.IOException)9 JsonSerializer (com.fasterxml.jackson.databind.JsonSerializer)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Version (com.fasterxml.jackson.core.Version)5 JsonParser (com.fasterxml.jackson.core.JsonParser)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)4 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)3 Test (org.junit.Test)3 Page (com.day.cq.wcm.api.Page)2 JsonPointer (com.fasterxml.jackson.core.JsonPointer)2 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)2 JavaType (com.fasterxml.jackson.databind.JavaType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SimpleDate (com.google.api.server.spi.types.SimpleDate)2 TopicPartition (org.apache.kafka.common.TopicPartition)2 Test (org.junit.jupiter.api.Test)2