From 3b180ed18a525aa3fc622bc5afa4f7d873d44d52 Mon Sep 17 00:00:00 2001 From: berryware <231598+berryware@users.noreply.github.com> Date: Tue, 19 May 2026 10:49:46 -0400 Subject: [PATCH 1/2] - convert json field name to camelCase before matching to protobuf object ____________________________________________________________________ Signed-off-by: berryware <231598+berryware@users.noreply.github.com> --- .../json/JsonCodecParseMethodGenerator.java | 2 +- .../src/main/proto/bytesAndString.proto | 2 +- .../hedera/pbj/integration/test/JsonCodecTest.java | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/impl/generators/json/JsonCodecParseMethodGenerator.java b/pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/impl/generators/json/JsonCodecParseMethodGenerator.java index 58f71603c..e18c03b1b 100644 --- a/pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/impl/generators/json/JsonCodecParseMethodGenerator.java +++ b/pbj-core/pbj-compiler/src/main/java/com/hedera/pbj/compiler/impl/generators/json/JsonCodecParseMethodGenerator.java @@ -77,7 +77,7 @@ static String generateParseObjectMethod(final String modelClassName, final List< // -- EXTRACT VALUES FROM PARSE TREE --------------------------------------------- for (JSONParser.PairContext kvPair : root.pair()) { - switch (kvPair.STRING().getText()) { + switch (toJsonFieldName(kvPair.STRING().getText())) { $caseStatements default: { if (strictMode) { diff --git a/pbj-integration-tests/src/main/proto/bytesAndString.proto b/pbj-integration-tests/src/main/proto/bytesAndString.proto index a8794eb3a..71c46a968 100644 --- a/pbj-integration-tests/src/main/proto/bytesAndString.proto +++ b/pbj-integration-tests/src/main/proto/bytesAndString.proto @@ -13,5 +13,5 @@ option java_multiple_files = true; */ message MessageWithBytesAndString { bytes bytesField = 1; - string stringField = 2; + string string_field = 2; } diff --git a/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java b/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java index b9929e4e2..39df75488 100644 --- a/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java +++ b/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java @@ -136,4 +136,17 @@ public void NullStringTest() throws Exception { assertNotEquals(0, bytesAndString.bytesField().length()); assertTrue(bytesAndString.stringField().isEmpty()); } + + @Test + public void SnakeCaseStringTest() throws Exception { + final String json = """ + { + "bytesField": "308201a2300d06092a86", + "string_field": "snake_case" + } + """; + MessageWithBytesAndString bytesAndString = MessageWithBytesAndString.JSON.parse(Bytes.wrap(json)); + assertNotEquals(0, bytesAndString.bytesField().length()); + assertEquals("snake_case", bytesAndString.stringField()); + } } From ae2906056b228e6cb010f3b271f69281bb067eb4 Mon Sep 17 00:00:00 2001 From: berryware <231598+berryware@users.noreply.github.com> Date: Tue, 19 May 2026 13:35:59 -0400 Subject: [PATCH 2/2] - revert the bytesAndString.proto - change method name casing to be java-like ____________________________________________________________________ Signed-off-by: berryware <231598+berryware@users.noreply.github.com> --- pbj-integration-tests/src/main/proto/bytesAndString.proto | 2 +- .../java/com/hedera/pbj/integration/test/JsonCodecTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pbj-integration-tests/src/main/proto/bytesAndString.proto b/pbj-integration-tests/src/main/proto/bytesAndString.proto index 71c46a968..a8794eb3a 100644 --- a/pbj-integration-tests/src/main/proto/bytesAndString.proto +++ b/pbj-integration-tests/src/main/proto/bytesAndString.proto @@ -13,5 +13,5 @@ option java_multiple_files = true; */ message MessageWithBytesAndString { bytes bytesField = 1; - string string_field = 2; + string stringField = 2; } diff --git a/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java b/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java index 39df75488..72dd9eeed 100644 --- a/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java +++ b/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java @@ -125,7 +125,7 @@ public void everythingTest() throws Exception { } @Test - public void NullStringTest() throws Exception { + public void nullStringTest() throws Exception { final String json = """ { "bytesField": "308201a2300d06092a86", @@ -138,7 +138,7 @@ public void NullStringTest() throws Exception { } @Test - public void SnakeCaseStringTest() throws Exception { + public void snakeCaseStringTest() throws Exception { final String json = """ { "bytesField": "308201a2300d06092a86",