How to generate fields of type {"type":"string","avro.java.string":"String"} using avro-tools-1.9.1.jar IDL?

Viewed 867

We have JAVA gradle avro plugin (davidmc24/gradle-avro-plugin) generate shema, and with default stringType string, which willl generated JAVA POJO like this:

Class A{
Shema = ...,{"type":"string","avro.java.string":"String"}...
string batchName;
}

then we use same avdl file to generate C# package, our solution is first generate avsc file with avro-tools-1.9.1.jar, which will generate avsc like this

"fields" : [ {
      "name" : "batchName",
      "type" : "string"
    },

WE have a C# producer , and java consumer, in this case , batchName can't been deserilize in JAVA consumer side, we got below error: org.apache.avro.util.Utf8 cannot be cast to java.lang.String

So, my guess is shema dissync, could you help point out how to let avro-tools-1.9.1.jar also generated fields with type avro.java.string keywords,so we can Thank you!

1 Answers

GenericDatumReader trade string and java.lang.String different code is here:

if (logicalType != null) {
  Conversion<?> conversion = getData().getConversionFor(logicalType);
  if (conversion != null) {
    return convert(datum, expected, logicalType, conversion);
  }
}

My solution will be using schema registry. And in common you will have first 1 to 5 bytes as schema ID in registry. You can desalinize the data using that schema. And get and genericRecord. I think this should solve your problem.

Related