Add simple Avro transformers

Unsophisticated Avro transformers for `SpecificRecord` implementations.

* * Fix DSL Factory

- transformer was changed to `<? extends GenericContainer>`; change the DSL to match

* * Restore test log4j

* * Revert to supporting only SpecificRecord

* * Fix assert

* * Add multi-type deserialization with fluent API
* Polishing for PR comments

* * Remove type mappings; Exxpression now returns the type (or class name)
* Cache types created from class names
* Add type header in "toAvro" transformer

* * Remove the type cache (already handled by the class loader)

* * Don't convert the class to String in the "toAvro" transformer
This commit is contained in:
Gary Russell
2019-07-09 14:59:01 -04:00
committed by Artem Bilan
parent 91156444c4
commit 9a2b75bae3
12 changed files with 1097 additions and 2 deletions

View File

@@ -373,7 +373,7 @@ public class Thing1 {
----
====
NOTE: The Boon support has been deprecated since version 5.2.
NOTE: Boon support has been deprecated since version 5.2.
You may wish to consider using a `FactoryBean` or a factory method to create the `JsonObjectMapper` with the required characteristics.
The following example shows how to use such a factory:
@@ -453,6 +453,19 @@ Starting with version 5.2, the `JsonToObjectTransformer` can be configured with
Also this component now consults request message headers first for the presence of the `JsonHeaders.RESOLVABLE_TYPE` or `JsonHeaders.TYPE_ID` and falls back to the configured type otherwise.
The `ObjectToJsonTransformer` now also populates a `JsonHeaders.RESOLVABLE_TYPE` header based on the request message payload for any possible downstream scenarios.
[[Avro-transformers]]
===== Apache Avro Transformers
Version 5.2 added simple transformers to transform to/from Apache Avro.
They are unsophisticated in that there is no schema registry; the transformers simply use the schema embedded in the `SpecificRecord` implementation generated from the Avro schema.
Messages sent to the `SimpleToAvroTransformer` must have a payload that implements `SpecificRecord`; the transformer can handle multiple types.
The `SimpleFromAvroTransformer` must be configured with a `SpecificRecord` class which is used as the default type to deserialize.
You can also specify a SpEL expression to determine the type to deserialize.
The default SpEL expression is `headers[avro_type]` (`AvroHeaders.TYPE`).
If the expression returns `null`, the `defaultType` is used.
[[transformer-annotation]]
==== Configuring a Transformer with Annotations

View File

@@ -116,3 +116,9 @@ See <<./webflux.adoc#webflux,WebFlux Support>> for more information.
The `MongoDbMessageStore` can now be configured with custom converters.
See <<./mongodb.adoc#mongodb, MongoDB Support>> for more information.
[[x5.2-avro]]
==== Avro Transformers
Simple Apache Avro transformers are now provided.
See <<./transformers.adoc#avro-transformers, Avro Transformers>> for more information.