我使用commercehub-oss gradle插件通过Avro协议生成Java类。
这是我的.avdl文件:
@namespace("com.abc.xyz")
protocol XYZ_Protocol_v1 {
record VendorItemInfo {
string vendorItemId;
long price;
string deliveryChargeType;
}
record XyzDto {
array<VendorItemInfo> vendorItemInfos;
}
}
基于commercehub-oss wiki,我运行$ gradle build来根据我的.avdl文件生成java文件。
然后当我向我的服务发出请求时,我得到了这个错误堆栈跟踪:
java.lang.ClassCastException: com.abc.xyz.domain.dto.VendorItemInfo cannot be cast to org.apache.avro.generic.IndexedRecord
org.apache.avro.generic.GenericData.getField(GenericData.java:666)
org.apache.avro.generic.GenericData.getField(GenericData.java:681)
org.apache.avro.generic.GenericDatumWriter.writeField(GenericDatumWriter.java:151)
org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:90)
org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:143)
org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:105)
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
org.apache.avro.generic.GenericDatumWriter.writeArray(GenericDatumWriter.java:179)
org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:107)
org.apache.avro.specific.SpecificDatumWriter.writeField(SpecificDatumWriter.java:87)
org.apache.avro.generic.GenericDatumWriter.writeRecord(GenericDatumWriter.java:143)
org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:105)
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:60)
任何想法如何解决这个问题?