Package jakarta.json.bind


package jakarta.json.bind
Provides the JSON Binding API, which enables binding Java objects to and from JSON documents.

The main entry point to the API is JsonbBuilder, which builds a Jsonb instance that you use to read and write JSON documents. For example,


   public record Lake(String name, int area, int maxDepth) {
   }

   String json = """
             [
              { "name": "Lake Superior", "area": 31700, "maxDepth": 1333 },
              { "name": "Lake Michigan", "area": 22300, "maxDepth": 925  },
              { "name": "Lake Huron",    "area": 23000, "maxDepth": 750  }
             ]
             """;

   Jsonb jsonb = JsonbBuilder.create();

   Lake[] lakes = jsonb.fromJson(json, Lake[].class);

   String name = lakes[0].name();     // "Lake Superior"
   int   depth = lakes[0].maxDepth(); // 1333

   String json_superior = jsonb.toJson(lakes[0]);

   // Close if no longer needed; a Jsonb instance should be reused throughout the application.
   jsonb.close();
 

The module Javadoc has additional examples.

Since:
JSON Binding 1.0
See Also: