IT lexicon › Programming › Gson

Gson

Programming På svenska → Updated: 2026-10-02
More info
Creator
Google
Released
Type
Java library
License
Apache 2.0
Source
github.com/google/gson

Google's Java library for turning objects into JSON and back, in two method calls and zero annotations.

Built internally at Google and open sourced in 2008. The appeal was the lack of ceremony: new Gson().toJson(obj) and fromJson(str, Foo.class) work on existing classes without modifying them, because the library reads fields via reflection. That contrasted sharply with contemporary Java libraries demanding XML configuration.

The trap is generics. Java erases type parameters at compile time, so List<Foo> cannot be expressed as an ordinary class literal, and the workaround is the cryptic new TypeToken<List<Foo>>(){}.getType() — an anonymous subclass whose only purpose is to preserve the type information. Gson dominated Android development for a decade before Kotlin serialization and Moshi took over.

← Back to the lexicon