Thanks, looks nice. I need to dig (much) more into acpect oriented
programming myself, so that I can use these stuff.

To update about issue: actually, the configuration[1] of avro-maven-plugin
works, what I was facing was some avro version incompatibility (between
minor versions). After resolving that, basic types are correctly generated
as String and correctly deserializes. However, what is not correctly
handled, and I'm sure about it this time, is arrays. Field definition like:

{
              "name": "codes",
              "type": ["null", {
                "type": "array",
                "name": "codeArray",
                "items": {
                  "type": "string"
                }
              }],
              "default": null
            }

will be cast in put method to List<String>, but individual items of that
array will be instances of Utf8. I'm writing you that, because your aspect
does not handle this situation.

Thanks for your help!
M.


[1]
 <configuration>
      <stringType>String</stringType>
      <fieldVisibility>PRIVATE</fieldVisibility>

po 21. 6. 2021 v 18:53 odesílatel Chad Preisler <chad.preis...@gmail.com>
napsal:

> 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.
>>>
>>

Reply via email to