Skip to content

helpdeveloper/gzip-json-jackson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Issues Forks Stars WorkFlow Codacy Badge Coverage Status Release Version JitPack

GZIP JSON Jackson

GZIP JSON Compressor with Jackson library.

This library uses Jackson library to convert your POJO to a compressed JSON with GZIP.

The goal of this library is to reduce the size of JSONs generated. However, if you have shorter JSON you don't have benefits in size, because the compressed output will be transformed in BASE64 and get more extensive than the original JSON.

Dependency

    <dependencies>
        <dependency>
            <groupId>com.github.helpdeveloper</groupId>
            <artifactId>gzip-json-jackson</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
        
    <!-- Include the Jitpack repository -->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

How to use

Just adding the GzipSerializable interface in your Object that will be converted and use your own ObjectMapper to convert. As we commonly do.

Sample

  • Include GzipSerializable in your object:
import br.com.helpdev.gzipjson.GzipSerializable;

class MyPojoClass implements GzipSerializable{
  private String name;
  //getters and setters
}
  • Sample using Jackson ObjectMapper:
import com.fasterxml.jackson.databind.ObjectMapper;

class MyServiceSample {
  
  private final ObjectMapper objectMapper;
  
  public MyService(final ObjectMapper objectMapper){
    this.objectMapper = objectMapper;
  }
  
  public String getCompressedJsonFromObject(final MyPojoClass pojo){
    return objectMapper.writeValueAsString(pojo);
  }
  
  public MyPojoClass getObjectFromCompressedJson(final String compressedJson){
    return objectMapper.readValue(compressedJson, MyPojoClass.class);
  }
}

Contribute

Pull Requests are welcome. For important changes, open an 'issue' first to discuss what you would like to change. Be sure to update tests as appropriate.

Developer

Guilherme Biff Zarelli

Blog/Site - https://helpdev.com.br LinkedIn - https://linkedin.com/in/gbzarelli/ GitHub - https://github.com/gbzarelli Medium - https://medium.com/@guilherme.zarelli Email - [email protected]

About

GZIP JSON Compressor with Jackson library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages