I created a point cut to work around this issue. @Aspect
public class SpecificRecordBasePutPointCut { public static final Logger LOGGER = LoggerFactory.getLogger(SpecificRecordBasePutPointCut.class); @Pointcut("execution(* your.package.for.generated.code.*.put(int, java.lang.Object)) && args(i, value)") void put(int i, java.lang.Object value) {} @Around("put(i, value)") public Object anyPutCall(ProceedingJoinPoint thisJoinPoint, int i, java.lang.Object value) throws Throwable { if (value != null) { LOGGER.debug("Value type is " + value.getClass().getName()); } if (value != null && (value instanceof Utf8 || value instanceof CharSequence)) { LOGGER.debug("In toString for i " + i); value = value.toString(); } LOGGER.debug("returning the i " + i); return thisJoinPoint.proceed(new Object[]{i, value}); } } On Mon, Jun 21, 2021 at 4:56 AM Martin Mucha <alfon...@gmail.com> wrote: > update after some research. > > It seems, that given configuration excerpt from my first mail actually > works. The `@AvroGenerated` class will generate String, and try to cast > Utf8 to String. > > The generated code looks like this: > > public void put(int field$, Object value$) { > switch(field$) { > case 0: > this.someField = (String)value$; > > which is indeed incorrect. > > According to: > > https://issues.apache.org/jira/browse/AVRO-2702 > > this should be solved in 1.10 (which it is not, incorrect code is still > generated). And if someone (like myself) is bound to 1.9.2 because of > confluent, there is no fix for this minor version branch at all. There are > some workarounds, but they do not cover all usecases, and for me the > situation has the only solution of just accepting avro-team decision, that > Utf8 is my favorite type now, and have to fix gazillion places in rather > huge project, which is just awesome. > > po 21. 6. 2021 v 11:17 odesÃlatel Martin Mucha <alfon...@gmail.com> > napsal: > >> It seems, that transition 1.8.2->1.9.2 brings backwards incomatibility and >> >> <configuration> >> <stringType>String</stringType> >> >> which did work to change generation from CharSequence to String, does not >> work any more. Within 15 minutes search I'm not unable to find literary any >> documentation of this plugin, so I don't know if there is some new way how >> to configure it for avro 1.9.2 and newer. >> >> Can someone advice? >> Thanks. >> >