Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Taylor Gray <tylgry@amazon.com>
  • Loading branch information
graytaylor0 committed Nov 14, 2024
1 parent 491d50a commit 963351c
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import org.apache.avro.LogicalType;
Expand Down Expand Up @@ -120,8 +121,9 @@ private void serialize(final Object datum, final StringBuilder buffer, final Ide
buffer.append("\"");
} else if (isBytes(datum)) {
final String bytesAsString = StandardCharsets.UTF_8.decode((ByteBuffer) datum).toString();
if (isBigDecimal(bytesAsString)) {
buffer.append(new BigDecimal(bytesAsString).doubleValue());
final Optional<BigDecimal> bytesAsBigDecimal = getBigDecimal(bytesAsString);
if (bytesAsBigDecimal.isPresent()) {
buffer.append(bytesAsBigDecimal.get().doubleValue());
} else {
buffer.append("{\"bytes\": \"");
ByteBuffer bytes = ((ByteBuffer) datum).duplicate();
Expand Down Expand Up @@ -192,12 +194,11 @@ private void writeEscapedString(String string, StringBuilder builder) {
builder.append(StringEscapeUtils.escapeJava(string));
}

private boolean isBigDecimal(String decimalString) {
private Optional<BigDecimal> getBigDecimal(String decimalString) {
try {
final BigDecimal bigDecimal = new BigDecimal(decimalString);
return true;
return Optional.of(new BigDecimal(decimalString));
} catch (final Exception e) {
return false;
return Optional.empty();
}
}
}

0 comments on commit 963351c

Please sign in to comment.