Unable to set a compression input/output decorator to a `SmileFactory`
See original GitHub issueI have a special need for the riak-java-client
which only allows me to use an ObjectMapper
to serialize/deserialize key-values, I would like to decorate a SmileFactory
with compressors like LZ4, Snappy or GZip but at the moment this is not possible, when I try a mapper like the following:
public static final Charset UTF8=Charset.forName("UTF-8");
public static final ObjectMapper GZIP_JSON_MAPPER=new ObjectMapper(new SmileFactory().disable(ENCODE_BINARY_AS_7BIT)
.setInputDecorator(new InputDecorator()
{
@Override
public InputStream decorate(IOContext context,InputStream inputStream) throws IOException
{
return new GZIPInputStream(inputStream);
}
@Override
public InputStream decorate(IOContext context,byte[] bytes,int offset,int length) throws IOException
{
return new GZIPInputStream(new ByteArrayInputStream(bytes,offset,length));
}
@Override
public Reader decorate(IOContext context,Reader reader) throws IOException
{
return new InputStreamReader(new GZIPInputStream(new ReaderInputStream(reader)),UTF8);
}
})
.setOutputDecorator(new OutputDecorator()
{
@Override
public OutputStream decorate(IOContext context,OutputStream outputStream) throws IOException
{
return new GZIPOutputStream(outputStream);
}
@Override
public Writer decorate(IOContext context,Writer writer) throws IOException
{
return new OutputStreamWriter(new GZIPOutputStream(new WriterOutputStream(writer,UTF8)));
}
}))
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS)
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
This is the exception I get:
Exception in thread "main" java.util.zip.ZipException: Not in GZIP format
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:165)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:79)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91)
at ...JsonUtils$4.decorate(JsonUtils.java:162)
at com.fasterxml.jackson.core.JsonFactory._decorate(JsonFactory.java:1459)
at com.fasterxml.jackson.dataformat.smile.SmileFactory.createParser(SmileFactory.java:330)
at com.fasterxml.jackson.dataformat.smile.SmileFactory.createParser(SmileFactory.java:320)
at com.fasterxml.jackson.dataformat.smile.SmileFactory.createParser(SmileFactory.java:29)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3091)
I used Gzip as an example, in reality I’m using both LZ4 and Gzip and both throw exceptions when I try with a SmileFactory
, this works perfectly with a JsonFactory
, the reason for me to prefer a SmileFactory
over a JsonFactory
is because it is notice-able faster than the JsonFactory
so basically it’ll help compensate the price I pay for compression.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
Input and other decorators and inheritance - angular
Show activity on this post. Decorators are not inherited. They need to be applied to the class used as component directly. Decorators on...
Read more >Angular Input Output Decorators & Directives
When we want to register our reusable component it is a good practice to create a shared module and to register and export...
Read more >qemu-img: error while compressing sector <NNN>
Description of problem: Converting a VMDK file to compressed qcow2 fails (reliably) in the same place each time. It does not appear to...
Read more >Chapter: Input Output - ROOT - CERN
13 Input/Output ... It includes a discussion on compression, and file recovery. ... To look at the physical layout of a ROOT file,...
Read more >3 Different Ways to Use Input Decorator
Input (@Input()) is one of the most used decorators in Angular apps. ... Well, there's another way by using set and get from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m using LZ4 double compression with 32KB block size, also because it is binary and Smile is faster than standard Json when I use some binary compression I’m using Smile straight forward, I’m using:
Here is the code for LZ4 Json mapper and LZ4 Smile mapper:
Thank so much for posting the code and for your detailed explanation. I’m gonna your configurations and see how it goes!!