From 82cda2a47beba338eecebe1165292bc4628bb1fc Mon Sep 17 00:00:00 2001 From: Marcello Date: Sun, 19 Jun 2022 19:16:36 +0100 Subject: [PATCH] feat(topicdata): allow integer/long to be serialized as float/double when using AVRO schema. (#1123) close #1122 --- src/main/java/org/akhq/utils/AvroSerializer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/akhq/utils/AvroSerializer.java b/src/main/java/org/akhq/utils/AvroSerializer.java index bf113d999..d21333ab8 100644 --- a/src/main/java/org/akhq/utils/AvroSerializer.java +++ b/src/main/java/org/akhq/utils/AvroSerializer.java @@ -123,13 +123,23 @@ private static Object objectSerializer(Object value, Schema schema) { case INT: return value; case LONG: - if (value != null && value instanceof Integer) { + if (value instanceof Integer) { return ((Integer) value).longValue(); } return value; case FLOAT: + if (value instanceof Integer) { + return ((Integer) value).floatValue(); + } else if (value instanceof Long) { + return ((Long) value).floatValue(); + } return value; case DOUBLE: + if (value instanceof Integer) { + return ((Integer) value).doubleValue(); + } else if (value instanceof Long) { + return ((Long) value).doubleValue(); + } return value; case BOOLEAN: return value;