avro-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Liu Bo <diabl...@gmail.com>
Subject set avro string type to String programmatically for generic record
Date Wed, 09 Mar 2016 13:49:56 GMT
Hi group

We are using avro generic record as message inside our streaming processing
The dynamic typing feature works greatly until we need to call remote http
service using json as the post body. The string values from the generic
record are serialized as utf8 object in JSON.

I decided to let avro deserialize strings to String instead of Utf8 to
avoid any further misuse of the Utf8 object.

One way to do this is add { "type": "string", "avro.java.string": "String" }
for every String type in our schema.
The other way I've found out is programmatically change it via:
GenericData.setStringType(schema, StringType.String);

So I write a simple method to do this after get schema from the config
center. The idea is traversal the schema tree and change the String for
type STRING, UNION, ARRAY, MAP(key and value I think). The code is attached
as a screenshot and it works.

My questions is "is there any drawbacks preventing me using this way"?
If this way is ok, is there anything missing in the attached method? Ps,
one method provided by avro to set the String type globally would be very
nice ;-)

Your help is greatly appreciated~~

All the best

Liu Bo

View raw message