Gson: Enjoy JSON (De-)Serialization in Java
Our learning package contains everything you need to know about Gson. Value your time & save yourself from endless hours of Google searches to quick fix your issues. Invest in your knowledge upfront & select the right package for you.
The book is based on Gson 2.8.
Extensive code samples are included, an additional workbook in the premium package.
This book is available in multiple packages!
Our learning package contains everything you need to know about Gson. Value your time & save yourself from endless hours of Google searches to quick fix your issues. Invest in your knowledge upfront & select the right package for you.
The book is based on Gson 2.8.
Extensive code samples are included, an additional workbook in the premium package.
About
About the Book
Learn Every Detail About Gson
Every modern Java application will need to do some Java-JSON parsing in their application life cycle. Gson is the most commonly used library to do the Java-JSON serialization and deserialization automatically.
Data parsing and mapping is complex. Even though Gson makes things quite simple, there are a lot of details that can trip your development up. If it's crazy data structures, weird variable names or complex dynamic data, you can lose a lot of time on something that should be done in minutes. Gson solves most problems in just a few lines. You just need to know the solutions!
This book includes an extensive introduction to Gson's features. We recommend to read it before you even have to use Gson for the first time. But even if you're already an avid user of Gson and stuck at a problem, we're confident we'll solve your problem.
Use our extensive bundle to learn about:
- Introduction to JSON & JSON-Java mapping
- Quick start to jump right into Gson
- Mapping of any Java type
- Deep dive into Gson's configuration options
- Practical examples of Gson customization
- Even advanced topics (Streaming, Generics, ...) are covered
- Necessary ProGuard configuration for Android app releases
Additionally, you'll get an extensive appendix:
- Combining a customized Gson with Retrofit 2
- Overview over common mistakes
- Exploration of Gson alternatives
Who Is This Book For?
This book is for Android or Java developers who want to get a substantial overview and reference book for Gson. You’ll benefit from the clearly recognizable code examples in regard to your daily work with Gson.
Rookie
If you’re just starting out with Gson (or coming from any other Java-JSON library like Jackson databind) this book will show you all important parts on how to work with Gson. The provided code snippets let you jumpstart and create the first mapping within minutes.
Expert
You already worked with Gson before? You’ll profit from our extensive code snippets and can improve your existing code base. Additionally, the book illustrates various optimizations for an even better performance.
Code Samples
Every code snippet in the book has been tested. We provide our test project as a leanpub extra. Feel free to download it and check the full code base as you move through the book. We try to keep the code snippets in the book as short as possible. If more context is necessary, the code examples should provide it.
Workbook
For the first time, we provide additional separated resources besides our book. The workbook gives you a chance to implement everything you'll learn in this book yourself. In our experience actually using a library like Gson helps to reinforce the newly gained knowledge. Thus, we've designed the workbook, which gives you a guided playground to experiment and learn the features of Gson.
Feedback
Packages
Pick Your Package
All packages include the ebook in the following formats: PDF, EPUB, and Web
Just The eBook
Minimum price
Suggested price$30.00$25.00
- Gson Sample CodeCode snippets of the book in action as an Android project.
eBook & Workbook
Minimum price
Suggested price$35.00$30.00
- Gson WorkbookThis packages Includes the Gson workbook (https://leanpub.com/gson-workbook).
- Gson Sample CodeCode snippets of the book in action as an Android project.
Author
About the Author
Contents
Table of Contents
About the Book
- What Topics Are Covered in This Book?
- Who Is This Book For?
- Code Examples
- Workbook
- Get the Workbook for Free
Chapter 1 — Introduction to Java-JSON Mapping
- Adding Gson as Dependency
- JSON Members, Properties & Fields
- Basics of Java-JSON Serialization
- Workbook Task A1
- Basics of Java-JSON Deserialization
- JSON Strings in Java
- Workbook Task A2
Chapter 2 — JSON Mapping with Gson
- Mapping of Nested Objects
- Workbook Task B1
- Automate Data Modelling
- Workbook Task B2
- Mapping of Arrays and Lists of Objects
- Keeping It Simple
- Workbook Task B3 & B5
- Workbook Task B4 & B6
- Multiple Property Names
- Lists Have to Be Consistent Objects
- Mapping of Maps
- Workbook Task B9
- Workbook Task B10
- Mapping of Sets
- Workbook Task B11
- Workbook Task B12
- Mapping of
NullValues - Mapping of Java Enums & Circular References
Chapter 3 — Gson Model Annotations
- How to Ignore Fields
- Workbook Task C1, C2 & C3
- How to Adjust the Naming of Fields
- Workbook Task C4 & C5
- Multiple Deserialization Names with
@SerializedName - Workbook Task C6
Chapter 4 — Configuring Gson with GsonBuilder
- GsonBuilder Basics
- Naming Policies
- Force Serialization of
nullValues - Workbook Task D1
- Go Beyond
transientand@Exposewith Exclusion Strategies - Workbook Task D2
- Relax Gson with Lenient
- Special Values of Floats/Doubles
- Workbook Task D3
- Model Versioning
- Workbook Task D4
- Formatting of Dates & Custom Date/Time Mapping
- Workbook Task D5 & D6
- Pretty Printing
- HTML Escaping
- Workbook Task D7
Chapter 5 — Advanced Gson Usage
- Mapping of Enums
- Workbook Task E1
- Workbook Task E2
- Mapping of Circular References
- Workbook Task E3
- Mapping of Generics
- Custom Serialization for Simplification (Part 1)
- Workbook Task E4
- Changing the Default Serialization with Custom Serialization (Part 2)
- Workbook Task E5
- Custom Deserialization Basics
- Workbook Task E6
- Custom Instance Creator
- Workbook Task E7
- Customizing (De)Serialization via @JsonAdapter
- Gson 2.7
- JsonElement, JsonArray & More
- Custom Deserialization for Calculated Fields
- On-The-Fly-Parsing With Streams
- Workbook Task F3
- Workbook Task F4
Chapter 6 — ProGuard Configuration
- Gson and ProGuard Are Not Best Friends
- Standard Gson Configuration
Chapter 7 — Practical Gson
- Low Level Parsing
- Workbook Task F1
- Storing Data in Android’s SharedPreferences With Gson
- How to Deserialize a List of Polymorphic Objects
- Unknown Types
- Workbook Task F2
Chapter 8 — Appendix
- Gson’s Configuration for Retrofit 2
- 5 Common Mistakes & Issues
- jsonschema2pojo.org
- Overview of Alternatives
- Gson’s Performance
Outro
- Workbook
- Talk to Us
Future Studio Books
- Retrofit
- Picasso
- Glide
- Future Studio Bundle
Contributors
About the Contributors
Marcus Pöhls
Marcus is an enthusiastic Android & Java developer. He’s developed multiple production-ready client and server applications. While following the core principle of performance for client apps, he also builds REST+JSON APIs that focus on clear and consistent design.
Besides his day job, sharing knowledge and teaching others has become a characteristic he never wants to miss.
Marcus has a Master’s degree in computer science from the Otto von Guericke University Magdeburg.
Feel free to get in touch on Twitter @marcuspoehls.
Christian Fellner
Christian is an experienced Software Engineer and consultant working with a wide variety of companies, ranging from startups to Fortune 500 companies.
His experiences range across a number of fields and technologies, including web and game development, virtual reality and machine learning.
Christian is an all-round nerd, passionate about outstanding design and creating innovational user experiences.
He has given training to many developers and students since 2011; explaining state of the art technologies and project management methodologies.
Christian has a BSc degree in Computer Systems in Engineering from the Otto von Guericke University Magdeburg.
Find him on Twitter: @celsiusF.
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earned over $14 million writing, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Write and Publish on Leanpub
You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!
Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.
Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.