Hi Marko,
You can easily convert Avro to JSON:
https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/io/JsonDecoder.java
https://github.com/apache/avro/blob/master/lang/java/avro/src/main/java/org/apache/avro/io/JsonEncoder.java
However, if you use union values, the structure is a bit awkward. For
example, it's very common for a JSON-encoded value to allow a value that's
either null or string. In Avro, that's trivially expressed as the union type
["null", "string"]. With conventional JSON, a string value "foo" would be
encoded just as "foo", which is easily distinguished from null when
decoding. However, when using the Avro JSON format it must be encoded
as {"string":
"foo"}.
You could easily define the whole protocol in an Avro AVDL:
https://avro.apache.org/docs/current/idl.html And generate POJO's from
there.
Hope this helps,
Cheers, Fokko
Op di 18 feb. 2020 om 00:21 schreef marko <[email protected]>:
> Our group has an number of services that interact with REST API’s. Those
> REST API documents are built by converting Domain Objects to Document
> DTO’s,
> then the DTO’s are serialized to JSON via Jackson.
>
> A (made-up) example might be a Car Domain Object that exposes itself and
> it’s Parts with REST endpoints. So there is a set of DTO’s that we
> maintain to assemble various REST Doc types (Engine, Wheel, Assembly,
> DamagedParts, etc…).
>
> Now we want to introduce Kafka messaging with structured Avro Schemas and
> generated Java Messages. The generated Java Avro Message Classes is what
> i'm referring to as "Avro DTO’s" (similar analogy of REST
> data-representation of the Domain)
>
> Ideally we could reuse our existing Json-DTO's and Domain<-> Json-DTO
> Converters, but I’m not sure if/how that is possible?
>
> Is there any way to stay DRY given we have Domain<->Json-DTO Converters,
> and
> now it seems like we have to create duplicate Domain<->Avro-DTO Converters?
>
> Is there any well-know way to streamline this situation that you know of?
>
> Thank you for your help.
>
>
>
>
> --
> Sent from: http://apache-avro.679487.n3.nabble.com/Avro-Users-f679479.html
>