guava-gson-serializers

Serialization support with GSON for Guava immutable collections

License

License

Categories

Categories

Gson Data JSON Guava General Purpose Libraries Utility
GroupId

GroupId

com.github.mike10004
ArtifactId

ArtifactId

guava-gson-serializers
Last Version

Last Version

0.6
Release Date

Release Date

Type

Type

jar
Description

Description

guava-gson-serializers
Serialization support with GSON for Guava immutable collections
Project URL

Project URL

https://github.com/mike10004/guava-gson-serializers
Source Code Management

Source Code Management

https://github.com/mike10004/guava-gson-serializers

Download guava-gson-serializers

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mike10004/guava-gson-serializers/ -->
<dependency>
    <groupId>com.github.mike10004</groupId>
    <artifactId>guava-gson-serializers</artifactId>
    <version>0.6</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mike10004/guava-gson-serializers/
implementation 'com.github.mike10004:guava-gson-serializers:0.6'
// https://jarcasting.com/artifacts/com.github.mike10004/guava-gson-serializers/
implementation ("com.github.mike10004:guava-gson-serializers:0.6")
'com.github.mike10004:guava-gson-serializers:jar:0.6'
<dependency org="com.github.mike10004" name="guava-gson-serializers" rev="0.6">
  <artifact name="guava-gson-serializers" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mike10004', module='guava-gson-serializers', version='0.6')
)
libraryDependencies += "com.github.mike10004" % "guava-gson-serializers" % "0.6"
[com.github.mike10004/guava-gson-serializers "0.6"]

Dependencies

compile (2)

Group / Artifact Type Version
com.google.guava : guava jar 28.1-jre
com.google.code.gson : gson jar 2.8.6

test (4)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-params jar 5.4.2
org.junit.jupiter : junit-jupiter-api jar 5.4.2
org.junit.jupiter : junit-jupiter-engine jar 5.4.2
org.assertj : assertj-core jar 3.14.0

Project Modules

There are no modules declared in this project.

guava-gson-serializers

Build Status Coverage Status Apache 2.0

Expanded Gson serialization for Guava ImmutableCollections, ImmutableMaps, and Optionals.

I originally included a TypeFactory for both Optional (java.util and Guava) but that was a long time ago and I think most people have switched over to java.util.Optional.

There are a lot of libraries that handle serialization of the Java 8 classes (Optional, Instant, etc) so I'll deprecate java.util.Optional factory and keep the original Guava factory and keep this library more Guava-centric.

Why?

Re-writing serializers is tedious!

How?

A few ways.

For a specific class..

Gson gson = new GsonBuilder().registerTypeAdapter(ImmutableList.class, new ImmutableListDeserializer()).create();

or, if the mood grabs you.. (but really don't do this)

Gson gson = new GsonBuilder().registerTypeAdapter(List.class, new ImmutableListDeserializer()).create();

or, the easiest way

public Gson getGson() {
  return ImmutableTypeAdapters.withImmutableCollectionSerializers(new GsonBuilder())
    .registerTypeAdapterFactory(OptionalTypeFactory.forJDK()) // you probably dont need this
    .create();
}

Optionals

JDK (deprecated)

Gson gson = new GsonBuilder().registerTypeAdapterFactory(OptionalTypeFactory.forJDK()).create();

Guava

Gson gson = new GsonBuilder().registerTypeAdapterFactory(OptionalTypeFactory.forGuava()).create();

What?

Currently supported
  • ImmutableList
  • ImmutableSet
  • ImmutableSortedSet
  • ImmutableBiMap
  • ImmutableMap
  • ImmutableBiMap
  • ImmutableSortedMap
  • Optionals (java.util and guava)

Future support (maybe)

  • ImmutableList/SetMultimap
  • Whatever anyone asks me to do

Where?

Github packages registry! https://maven.pkg.github.com/acebaggins/guava-gson-serializers

Who?

Built by me for the wonderful Guava and Gson libraries.

Versions

Version
0.6