Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JSON empty object or array bug #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/libraries/Gradle__org_objenesis_objenesis_2_6.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/runConfigurations.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ protected void doEncode(@NotNull Writer writer, @NotNull OpackValue opackValue)
currentContextIndex = this.decodeBaseStack.peek();
currentContext = (OpackValue) this.decodeValueStack.get(currentContextIndex);
currentContextType = currentContext.getClass();
literalMode = false;
}

break;
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/com/realtimetech/opack/test/codec/JsonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,36 @@ public void object_to_string_to_object() throws DecodeException, EncodeException
Assertions.assertEquals(opackValue1.toString(), opackValue2.toString());
}

@Test
public void empty_object() throws DecodeException, EncodeException {
String targetData = "{\"object\":{},\"value\":2147483648}";

JsonCodec jsonCodec = new JsonCodec.Builder().create();

OpackValue opackValue1 = jsonCodec.decode(targetData);

String middle = jsonCodec.encode(opackValue1);
OpackValue opackValue2 = jsonCodec.decode(middle);

Assertions.assertEquals(opackValue1, opackValue2);
Assertions.assertEquals(opackValue1.toString(), opackValue2.toString());
}

@Test
public void empty_array() throws DecodeException, EncodeException {
String targetData = "{\"array\":[],\"value\":2147483648}";

JsonCodec jsonCodec = new JsonCodec.Builder().create();

OpackValue opackValue1 = jsonCodec.decode(targetData);

String middle = jsonCodec.encode(opackValue1);
OpackValue opackValue2 = jsonCodec.decode(middle);

Assertions.assertEquals(opackValue1, opackValue2);
Assertions.assertEquals(opackValue1.toString(), opackValue2.toString());
}

@Test
public void string_to_object_to_string_object() throws DecodeException, EncodeException {
OpackValue opackValue = CommonOpackValue.create();
Expand Down