Home

GsonBuilder

GsonBuilder is a component of the Google Gson library for Java, used to construct configurable Gson instances. It follows the builder pattern, allowing chaining of configuration methods, with create() producing the final Gson object.

Among configurable options are pretty printing (setPrettyPrinting), suppression or escaping of HTML characters (disableHtmlEscaping), and whether

GsonBuilder supports registering custom type adapters and factories to handle specific types, via registerTypeAdapter(Type, Object) and

Once configured, calling create() returns a Gson instance that is ready to use. Gson instances produced by

to
include
null
fields
(serializeNulls).
You
can
control
which
fields
are
serialized
by
using
excludeFieldsWithoutExposeAnnotation()
or
excludeFieldsWithModifiers(int),
and
you
can
customize
how
Java
field
names
map
to
JSON
keys
with
setFieldNamingPolicy(...)
or
setFieldNamingStrategy(...).
Date
handling
is
configurable
via
setDateFormat(...).
Version-based
inclusion
can
be
controlled
with
setVersion(double).
You
can
also
enable
lenient
parsing
with
setLenient().
registerTypeAdapterFactory(...).
You
can
provide
custom
serializers,
deserializers,
and
TypeAdapters
for
complex
objects
and
for
third-party
types.
There
is
also
support
for
instance
creators
and
exclusion
strategies
to
fine-tune
serialization
and
deserialization.
GsonBuilder
are
thread-safe
and
reusable
across
the
application.