Search in sources :

Example 1 with CBORFactory

use of com.fasterxml.jackson.dataformat.cbor.CBORFactory in project jvm-serializers by eishay.

the class JacksonWithAfterburner method registerCBOR.

public static void registerCBOR(TestGroups groups) {
    ObjectMapper mapper = new ObjectMapper(new CBORFactory());
    mapper.registerModule(new AfterburnerModule());
    groups.media.add(JavaBuiltIn.mediaTransformer, new StdJacksonDataBind<MediaContent>("cbor/jackson+afterburner/databind", MediaContent.class, mapper), new SerFeatures(SerFormat.BINARY, SerGraph.FLAT_TREE, SerClass.ZERO_KNOWLEDGE, STD_DESC));
}
Also used : AfterburnerModule(com.fasterxml.jackson.module.afterburner.AfterburnerModule) CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) MediaContent(data.media.MediaContent) SerFeatures(serializers.SerFeatures) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with CBORFactory

use of com.fasterxml.jackson.dataformat.cbor.CBORFactory in project elasticsearch by elastic.

the class CborXContentTests method testBigInteger.

public void testBigInteger() throws Exception {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    JsonGenerator generator = new CBORFactory().createGenerator(os);
    doTestBigInteger(generator, os);
}
Also used : CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 3 with CBORFactory

use of com.fasterxml.jackson.dataformat.cbor.CBORFactory in project spring-framework by spring-projects.

the class AnnotationDrivenBeanDefinitionParser method getMessageConverters.

private ManagedList<?> getMessageConverters(Element element, Object source, ParserContext parserContext) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> messageConverters = new ManagedList<>();
    if (convertersElement != null) {
        messageConverters.setSource(source);
        for (Element beanElement : DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
            Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
            messageConverters.add(object);
        }
    }
    if (convertersElement == null || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
        messageConverters.setSource(source);
        messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source));
        RootBeanDefinition stringConverterDef = createConverterDefinition(StringHttpMessageConverter.class, source);
        stringConverterDef.getPropertyValues().add("writeAcceptCharset", false);
        messageConverters.add(stringConverterDef);
        messageConverters.add(createConverterDefinition(ResourceHttpMessageConverter.class, source));
        messageConverters.add(createConverterDefinition(SourceHttpMessageConverter.class, source));
        messageConverters.add(createConverterDefinition(AllEncompassingFormHttpMessageConverter.class, source));
        if (romePresent) {
            messageConverters.add(createConverterDefinition(AtomFeedHttpMessageConverter.class, source));
            messageConverters.add(createConverterDefinition(RssChannelHttpMessageConverter.class, source));
        }
        if (jackson2XmlPresent) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2XmlHttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonFactoryDef.getPropertyValues().add("createXmlMapper", true);
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        } else if (jaxb2Present) {
            messageConverters.add(createConverterDefinition(Jaxb2RootElementHttpMessageConverter.class, source));
        }
        if (jackson2Present) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2HttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        } else if (gsonPresent) {
            messageConverters.add(createConverterDefinition(GsonHttpMessageConverter.class, source));
        }
        if (jackson2SmilePresent) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2SmileHttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonFactoryDef.getPropertyValues().add("factory", new SmileFactory());
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        }
        if (jackson2CborPresent) {
            RootBeanDefinition jacksonConverterDef = createConverterDefinition(MappingJackson2CborHttpMessageConverter.class, source);
            GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
            jacksonFactoryDef.getPropertyValues().add("factory", new CBORFactory());
            jacksonConverterDef.getConstructorArgumentValues().addIndexedArgumentValue(0, jacksonFactoryDef);
            messageConverters.add(jacksonConverterDef);
        }
    }
    return messageConverters;
}
Also used : SourceHttpMessageConverter(org.springframework.http.converter.xml.SourceHttpMessageConverter) AtomFeedHttpMessageConverter(org.springframework.http.converter.feed.AtomFeedHttpMessageConverter) CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) Element(org.w3c.dom.Element) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) ManagedList(org.springframework.beans.factory.support.ManagedList) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) SmileFactory(com.fasterxml.jackson.dataformat.smile.SmileFactory) RssChannelHttpMessageConverter(org.springframework.http.converter.feed.RssChannelHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)

Example 4 with CBORFactory

use of com.fasterxml.jackson.dataformat.cbor.CBORFactory in project immutables by immutables.

the class GsonJacksonBridgeSerializationTest method cborFactoryTest.

@Test
public void cborFactoryTest() throws IOException {
    TestObject value = createTestObject();
    CBORFactory factory = new CBORFactory();
    Class<TestObject> clazz = TestObject.class;
    ByteArrayOutputStream outputStream = testWriting(value, factory, clazz);
    TestObject value2 = testReading(factory, clazz, outputStream);
    Assert.assertEquals(value2.toString(), value.toString());
}
Also used : CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with CBORFactory

use of com.fasterxml.jackson.dataformat.cbor.CBORFactory in project nutch by apache.

the class CommonCrawlDataDumper method serializeCBORData.

private byte[] serializeCBORData(String jsonData) {
    CBORFactory factory = new CBORFactory();
    CBORGenerator generator = null;
    ByteArrayOutputStream stream = null;
    try {
        stream = new ByteArrayOutputStream();
        generator = factory.createGenerator(stream);
        // Writes CBOR tag
        writeMagicHeader(generator);
        generator.writeString(jsonData);
        generator.flush();
        stream.flush();
        return stream.toByteArray();
    } catch (Exception e) {
        LOG.warn("CBOR encoding failed: " + e.getMessage());
    } finally {
        try {
            generator.close();
            stream.close();
        } catch (IOException e) {
        // nothing to do
        }
    }
    return null;
}
Also used : CBORFactory(com.fasterxml.jackson.dataformat.cbor.CBORFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) CBORGenerator(com.fasterxml.jackson.dataformat.cbor.CBORGenerator) ParseException(java.text.ParseException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

CBORFactory (com.fasterxml.jackson.dataformat.cbor.CBORFactory)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CBORGenerator (com.fasterxml.jackson.dataformat.cbor.CBORGenerator)1 SmileFactory (com.fasterxml.jackson.dataformat.smile.SmileFactory)1 AfterburnerModule (com.fasterxml.jackson.module.afterburner.AfterburnerModule)1 MediaContent (data.media.MediaContent)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ParseException (java.text.ParseException)1 Test (org.junit.Test)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1 ManagedList (org.springframework.beans.factory.support.ManagedList)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)1 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)1 AtomFeedHttpMessageConverter (org.springframework.http.converter.feed.AtomFeedHttpMessageConverter)1 RssChannelHttpMessageConverter (org.springframework.http.converter.feed.RssChannelHttpMessageConverter)1 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)1