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.
<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>
Just adding the GzipSerializable
interface in your
Object that will be converted and use your own ObjectMapper
to convert. As we commonly do.
- 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);
}
}
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.
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 - gbzarelli@helpdev.com.br