Skip to content

Commit

Permalink
Fix(topic data): upcast JSON integer to Long when needed for Avro sch…
Browse files Browse the repository at this point in the history
…ema (#778)

Fixes #757
  • Loading branch information
Tim te Beek authored and tchiotludo committed Oct 24, 2021
1 parent a5a7eb8 commit 185594c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/akhq/utils/AvroSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ private static Object objectSerializer(Object value, Schema schema) {
case INT:
return value;
case LONG:
if (value != null && value instanceof Integer) {
return ((Integer) value).longValue();
}
return value;
case FLOAT:
return value;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/org/akhq/utils/AvroDeserializerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ static Stream<Arguments> convertionSource() {
Arguments.of("abc", "\"bytes\"", "abc".getBytes()),
Arguments.of("10.10", "{\"type\": \"bytes\", \"logicalType\": \"decimal\", \"scale\": 2, \"precision\": 4}", new BigDecimal("10.10")),
Arguments.of("26910000000000000000000000000258.00000", "{\"type\": \"bytes\", \"logicalType\": \"decimal\", \"scale\": 5, \"precision\": 37}", new BigDecimal("26910000000000000000000000000258.00000")),
Arguments.of(1, "[\"null\",\"long\"]", 1L),
Arguments.of(uuid.toString(), "{\"type\": \"string\", \"logicalType\": \"uuid\"}", uuid),
Arguments.of(LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE), "{\"type\": \"int\", \"logicalType\": \"date\"}", LocalDate.now()),
Arguments.of(localTime.format(DateTimeFormatter.ISO_LOCAL_TIME), "{\"type\": \"long\", \"logicalType\": \"time-micros\"}", localTime),
Expand Down

0 comments on commit 185594c

Please sign in to comment.