rk3rn3r commented on a change in pull request #1052: URL: https://github.com/apache/camel-kafka-connector/pull/1052#discussion_r581193345
########## File path: core/src/main/java/org/apache/camel/kafkaconnector/CamelSinkTask.java ########## @@ -225,15 +230,47 @@ If the CamelMainSupport instance fails to be instantiated (ie.: due to missing c } } - private static void mapHeader(Header header, String prefix, Map<String, Object> destination) { + private void mapHeader(Header header, String prefix, Map<String, Object> destination) { final String key = StringHelper.after(header.key(), prefix, header.key()); final Schema schema = header.schema(); if (schema.type().equals(Schema.BYTES_SCHEMA.type()) && Objects.equals(schema.name(), Decimal.LOGICAL_NAME)) { destination.put(key, Decimal.toLogical(schema, (byte[]) header.value())); } else { - destination.put(key, header.value()); + destination.put(key, convertValueFromStruct(header.schema(), header.value())); + } + } + + private Object convertValueFromStruct(Schema schema, Object value) { + // if we have have the struct to map flag enabled and + // if we have a schema of type Struct, we convert it to map, otherwise + // we just return the value as it is + if (convertStructToMap && schema != null && value != null && Schema.Type.STRUCT == schema.type()) { + return toMap((Struct) value); } + + return value; + } + + private static Map<String, Object> toMap(final Struct struct) { + final HashMap<String, Object> fieldsToValues = new HashMap<>(); + + struct.schema().fields().forEach(field -> { + try { + Object value = struct.get(field); + + // recursive call if we have nested structs + if (value instanceof Struct) { + fieldsToValues.put(field.name(), toMap((Struct) value)); + } else { + fieldsToValues.put(field.name(), value); + } + } catch (DataException e) { Review comment: Isn't DataException only happening on putting content into a Struct but not when adding to a Map? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org