liveBook · Manning

Gson

As explained in Data-Oriented Programming: Reduce software complexity

Gson is a Java library for converting Java objects to JSON and JSON text back to Java objects.

A web service receives a search request as JSON. In Java, Gson turns that string into a generic map, avoiding a custom request class when the payload is data-shaped. section 11.3

Gson supports two complementary edges of a data flow:

  • Parse JSON text into a Java Map with gson.fromJson(jsonString, Map.class). section 11.3
  • Serialize map values according to their runtime types: numbers remain unquoted, while strings receive quotes. section 10.1

Parsing a search request

Given {"title":"habit","fields":["title","weight","number_of_pages"]}, Gson produces a generic map that a service can inspect before handling the search. section 11.3

Listing 11.3 Parsing a JSON string in Java with Gson
var jsonString = 
  '{"title":"habit","fields":["title","weight","number_of_pages"]}';
gson.fromJson(jsonString, Map.class);

Shows the Java Gson parsing fragment for converting a JSON string into a map. section 11.3

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Demonstrates map parsing and runtime-type serialization, but stops short of detailed API behavior or object-mapping internals.
Examples
Uses a book-search payload and a database result containing titles, ISBNs, and publication years.
What it assumes
Assumes Java, JSON strings, maps, and web-service requests while teaching manual parsing through a concrete payload.
What you can do after
Apply it via Gson to parse a JSON string into a Java Map.
How it connects
Connects JSON, Java maps, web services, database results, and JSON schema.

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.