public void convert()

in library/camel-kamelets-utils/src/main/java/org/apache/camel/kamelets/utils/format/converter/avro/AvroStructDataType.java [43:59]


    public void convert(Exchange exchange) {
        AvroSchema schema = exchange.getProperty(SchemaHelper.CONTENT_SCHEMA, AvroSchema.class);

        if (schema == null) {
            throw new CamelExecutionException("Missing proper avro schema for data type processing", exchange);
        }

        try {
            Object unmarshalled = Avro.MAPPER.reader().forType(JsonNode.class).with(schema)
                    .readValue(getBodyAsStream(exchange));
            exchange.getMessage().setBody(unmarshalled);

            exchange.getMessage().setHeader(Exchange.CONTENT_TYPE, MimeType.STRUCT.type());
        } catch (InvalidPayloadException | IOException e) {
            throw new CamelExecutionException("Failed to apply Avro x-struct data type on exchange", exchange, e);
        }
    }