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));
}
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);
}
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;
}
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());
}
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;
}
Aggregations