Skip to content

Commit

Permalink
Fix decimal mapping when value is array (#1357)
Browse files Browse the repository at this point in the history
Added missing return, when processing big decimal field which has its value in byte array format.
Previously algorithm would do the mapping, set the values, but would not exit with return and fallback to IllegalArgumentException at the end of the method.

Fixes #1356☕️
  • Loading branch information
ramasLTU committed Oct 18, 2021
1 parent b705783 commit 21b9e25
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ private static void fillField(
}
}
protoMsg.setField(fieldDescriptor, bytes);
return;
} catch (JSONException e) {
throw new IllegalArgumentException(
String.format("Error: " + currentScope + "could not be converted to byte[]."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private static void fillField(
}
}
protoMsg.setField(fieldDescriptor, bytes);
return;
} catch (JSONException e) {
throw new IllegalArgumentException(
String.format("Error: " + currentScope + "could not be converted to byte[]."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public class JsonToProtoMessageTest {
.put(
BytesType.getDescriptor(),
new Message[] {
BytesType.newBuilder().setTestFieldType(ByteString.copyFromUtf8("test")).build()
BytesType.newBuilder().setTestFieldType(ByteString.copyFromUtf8("test")).build(),
BytesType.newBuilder()
.setTestFieldType(ByteString.copyFrom(new byte[] {1, 2, 3}))
.build()
})
.put(
Int64Type.getDescriptor(),
Expand Down Expand Up @@ -599,7 +602,8 @@ public void testAllTypes() throws Exception {
e.getMessage());
}
}
if (entry.getKey() == Int64Type.getDescriptor()) {
if (entry.getKey() == Int64Type.getDescriptor()
|| entry.getKey() == BytesType.getDescriptor()) {
assertEquals(entry.getKey().getFullName(), 2, success);
} else {
assertEquals(entry.getKey().getFullName(), 1, success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ public class JsonToProtoMessageTest {
.put(
BytesType.getDescriptor(),
new Message[] {
BytesType.newBuilder().setTestFieldType(ByteString.copyFromUtf8("test")).build()
BytesType.newBuilder().setTestFieldType(ByteString.copyFromUtf8("test")).build(),
BytesType.newBuilder()
.setTestFieldType(ByteString.copyFrom(new byte[] {1, 2, 3}))
.build()
})
.put(
Int64Type.getDescriptor(),
Expand Down Expand Up @@ -600,7 +603,8 @@ public void testAllTypes() throws Exception {
e.getMessage());
}
}
if (entry.getKey() == Int64Type.getDescriptor()) {
if (entry.getKey() == Int64Type.getDescriptor()
|| entry.getKey() == BytesType.getDescriptor()) {
assertEquals(entry.getKey().getFullName(), 2, success);
} else {
assertEquals(entry.getKey().getFullName(), 1, success);
Expand Down

0 comments on commit 21b9e25

Please sign in to comment.