Android Gson

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Gson is a Java library that can be used to convert Java Objects into their JSON representation. Gson considers both of these as very important design goals.

Gson Features:

Provide simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa

Allow pre-existing unmodifiable objects to be converted to and from JSON

Extensive support of Java Generics

Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)

Syntax

  • Excluder excluder()
  • FieldNamingStrategy fieldNamingStrategy()
  • <T> T fromJson(JsonElement json, Class<T> classOfT)
  • <T> T fromJson(JsonElement json, Type typeOfT)
  • <T> T fromJson(JsonReader reader, Type typeOfT)
  • <T> T fromJson(Reader json, Class<T> classOfT)
  • <T> T fromJson(Reader json, Type typeOfT)
  • <T> T fromJson(String json, Class<T> classOfT)
  • <T> T fromJson(String json, Type typeOfT)
  • <T> TypeAdapter<T> getAdapter(Class<T> type)
  • <T> TypeAdapter<T> getAdapter(TypeToken<T> type)
  • <T> TypeAdapter<T> getDelegateAdapter(TypeAdapterFactory skipPast, TypeToken<T> type)
  • JsonReader newJsonReader(Reader reader)
  • JsonWriter newJsonWriter(Writer writer)
  • JsonElement toJsonTree(Object src)
  • JsonElement toJsonTree(Object src, Type typeOfSrc)
  • boolean serializeNulls()
  • boolean htmlSafe()
  • String toJson(JsonElement jsonElement)
  • String toJson(Object src)
  • String toJson(Object src, Type typeOfSrc)
  • String toString()
  • void toJson(Object src, Type typeOfSrc, Appendable writer)
  • void toJson(Object src, Type typeOfSrc, JsonWriter writer)
  • void toJson(JsonElement jsonElement, Appendable writer)
  • void toJson(JsonElement jsonElement, JsonWriter writer)
  • void toJson(Object src, Appendable writer)


Got any Android Question?