Skip to content

Commit

Permalink
WireType.JSON_ONLY incorrectly parses nested maps #844 (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed Mar 11, 2024
1 parent 1872409 commit bcfb9d4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/openhft/chronicle/wire/JSONWire.java
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,7 @@ private Object parseType() throws InvalidMarshallableException {
final Class<?> clazz = classLookup().forName(sb.subSequence(1, sb.length()));
Object object = parseType(null, clazz, true);
consume('}');
consumePadding(1);
return object;
}
}
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/net/openhft/chronicle/wire/issue/Issue844Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package net.openhft.chronicle.wire.issue;

import net.openhft.chronicle.wire.WireTestCommon;
import net.openhft.chronicle.wire.WireType;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class Issue844Test extends WireTestCommon {

@Test
public void nestedMapsJson() {

// at least 3 levels of nested to reproduce this issue
Object o2 = WireType.JSON_ONLY.fromString("\"serviceConfig\": {\n" +
" \"db\": {\n" +
" \"a\": {\n" +
" \"Hello\": \"World\"\n" +
" },\n" +
" \"mongodb\": {\n" +
" \"@net.openhft.chronicle.wire.issue.Issue844Test$Enum\": \"INSTANCE\"\n" +
" },\n" +
" \"collection\": \"ladder\"\n" +
" }\n" +
"}");
assertEquals(
"serviceConfig: {\n" +
" db: {\n" +
" a: {\n" +
" Hello: World\n" +
" },\n" +
" mongodb: !net.openhft.chronicle.wire.issue.Issue844Test$Enum INSTANCE,\n" +
" collection: ladder\n" +
" }\n" +
"}\n",
WireType.YAML_ONLY.asString(o2));
assertEquals(
"{\"serviceConfig\":{\"db\":{\"a\":{\"Hello\":\"World\"},\"mongodb\":{\"@net.openhft.chronicle.wire.issue.Issue844Test$Enum\":\"INSTANCE\"},\"collection\":\"ladder\"}}}",
WireType.JSON_ONLY.asString(o2)
);
}


public enum Enum {
INSTANCE
}

}

0 comments on commit bcfb9d4

Please sign in to comment.