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 58f71603..e18c03b1 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/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java b/pbj-integration-tests/src/test/java/com/hedera/pbj/integration/test/JsonCodecTest.java index b9929e4e..72dd9eee 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", @@ -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()); + } }