I'm thinking that because of the usage of this scenario I only need to 
implement one method for each decorator like in the following example?


  static {
    final SmileFactory smileFactory=new 
SmileFactory().disable(ENCODE_BINARY_AS_7BIT);
    smileFactory.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 i,int 
i1)
      {
        return null;
      }

      @Override
      public Reader decorate(IOContext ioContext,Reader reader)
      {
        return null;
      }
    });

    smileFactory.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)
      {
        return null;
      }
    });

    GZIP_SMILE_MAPPER=new ObjectMapper(smileFactory).
       disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES).
       disable(SerializationFeature.FAIL_ON_EMPTY_BEANS).
       setSerializationInclusion(JsonInclude.Include.NON_NULL).
       disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS).
       registerModule(INT_RANGE_MODULE).
       registerModule(JODA_MODULE).
       registerModule(TAGS_MODULE);
  }

Thanks again for your support and great framework ;-)
Guido.

On Saturday, November 24, 2018 at 10:56:21 AM UTC, [email protected] wrote:
>
> Hi Tatu,
>
> This looks exactly like what I need, I know this is not a responsibility 
> of the *ObjectMapper* but the 3rd party API isn't giving me much freedom 
> so I cannot compress myself,
> I'm wondering if I can decorate the *SmileFactory* using this approach? 
> As the SmileFactory without the extra string compression is the fastest of 
> the bunch.
> Also, are there examples on how to use these Input/Output decorators, 
> thanks a lot for answering as this is a huge step towards the solution.
>
> Guido.
>
> On Saturday, November 24, 2018 at 4:37:54 AM UTC, Tatu Saloranta wrote:
>>
>> On Fri, Nov 23, 2018 at 8:17 PM <[email protected]> wrote: 
>> > 
>> > Hi, 
>> > 
>> > I have been scratching my head for the last hour or two looking for a 
>> Gzip JsonFactory or any other type of factory that is able to compress huge 
>> Json objects, 
>> > I know I'm going to sacrifice some performance but for this particular 
>> scenario I need a JsonFactory -or ObjectMapper- that is able to gzip. 
>> > Is there any opensource project that has that done already? or what 
>> would be the simplest way to write one? 
>> > I could gzip the output of the ObjectMapper but this is not an option 
>> before I'm using a 3rd party framework that requires me to pass an 
>> ObjectMapper 
>>
>> This sort of falls outside realm of ObjectMapper in my opinion (and 
>> why just gzip? Snappy, lz4, bz2, there's plethora of compression 
>> codecs to support). 
>>
>> But there is one extension point in JsonFactory (part of `jackson-core`): 
>>
>> JsonFactory.setOutputDecorator(OutputDecorator decoratorImpl); 
>>
>> which you can use to install a decorator that will add compression 
>> codec into `OutputStream` when `decorate(OutputStream)` method is 
>> called. 
>> So you can construct and configure `JsonFactory`, construct 
>> `ObjectMapper` with it, and that should allow you to add compression. 
>>
>> I hope this helps, 
>>
>> -+ Tatu +- 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"jackson-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to