Skip to content

fix: Allow the JSON parsing of Strings with a null value.#829

Merged
anthony-swirldslabs merged 1 commit into
hashgraph:mainfrom
berryware:828-allow-json-null-strings
May 18, 2026
Merged

fix: Allow the JSON parsing of Strings with a null value.#829
anthony-swirldslabs merged 1 commit into
hashgraph:mainfrom
berryware:828-allow-json-null-strings

Conversation

@berryware
Copy link
Copy Markdown
Contributor

  • Check STRING() for null before getting its value. If null set value to null else to the parsed string.

Description:
The Block Node(BN) Team would like to use PBJ, rather than GSON, to parse JSON responses from the Mirror Node(MN) REST API. The MN Response can contain string fields with null values. PBJ throws an exception when parsing null values.

com.hedera.pbj.runtime.ParseException: com.hedera.pbj.runtime.ParseException: java.lang.NullPointerException: Cannot invoke "org.antlr.v4.runtime.tree.TerminalNode.getText()" because the return value of "com.hedera.pbj.runtime.jsonparser.JSONParser$ValueContext.STRING()" is null.

Related issue(s):

Fixes #828

Notes for reviewer:
spotless made some formatting changes in addition to my changes.

Checklist

  • Documented (Code comments, README, etc.)
  • Tested (unit, integration, etc.)

… to null else to the parsed string.

____________________________________________________________________
Signed-off-by: berryware <231598+berryware@users.noreply.github.com>
@berryware berryware requested review from a team as code owners May 16, 2026 20:23
@berryware
Copy link
Copy Markdown
Contributor Author

@jsync-swirlds @Nana-EC for visibility

Copy link
Copy Markdown
Contributor

@anthony-swirldslabs anthony-swirldslabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, @berryware . Thank you!

@anthony-swirldslabs anthony-swirldslabs merged commit e95f3ae into hashgraph:main May 18, 2026
16 of 19 checks passed
@anthony-swirldslabs
Copy link
Copy Markdown
Contributor

This PR will be released in PBJ v0.15.4 shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing a JSON string with a value of "null" throws an exception

2 participants