Java 17 String to JSON with Glassfish' jakarta.json

To read a Java String with Jakarta JSON Processing (JSON-P) into a jakarta.json.JsonObject with Glassfish' implementation add the following dependency to your pom.xml:


Now a JsonObject can be created from a String:

import org.junit.jupiter.api.Test;
import jakarta.json.Json;

public class JsonpWithGlassfishTest {

    public void parseJSON() {
        var expected = "glassfish";
        var json = """
        try (var stringReader = new StringReader(json)){
            var jsonObject = Json.createReader(stringReader).readObject();
            var actual = jsonObject.getString("hello");
            assertEquals(expected, actual);


Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
...the last 150 posts
...the last 10 comments