You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@avro.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2023/04/12 05:36:00 UTC

[jira] [Updated] (AVRO-3262) Include Avro record class name in toString

     [ https://issues.apache.org/jira/browse/AVRO-3262?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ASF GitHub Bot updated AVRO-3262:
---------------------------------
    Labels: pull-request-available  (was: )

> Include Avro record class name in toString
> ------------------------------------------
>
>                 Key: AVRO-3262
>                 URL: https://issues.apache.org/jira/browse/AVRO-3262
>             Project: Apache Avro
>          Issue Type: Improvement
>    Affects Versions: 1.11.0
>            Reporter: Dan Newton
>            Priority: Minor
>              Labels: pull-request-available
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Avro objects output JSON when they are `toString`'d.
> This makes it difficult to understand what Avro objects are being logged when passing the whole object into the logging string.
> It would be convenient if it contained the class name of the Avro object, so that when used in strings or logging its easier to read.
> Note, this could be bypassed manually in user code by writing something like `"logging ${avroObject::class.java.name} $avroObject"` (I'd write it in Java but my head hurts right now).
> From what I looked at, possibly changing `SpecificRecordBase.toString` to the following would resolve the issue:
>  
> {code:java}
> @Override
> public String toString() {
>   return this.class + " " + getSpecificData().toString(this);
> }{code}
>  
> Possibly the solution might be more elegant than that or in a slightly different place.
> The solution above assumes that the `toString` isn't being used for anything within the Avro code. If other code depends on the fact it outputs JSON then what I've suggested won't be suitable.
> In that situation, we could add a new method that contains the class name which can be called from user code and is still an improvement.
> On the flip side, the JSON only output could be moved and called from other Avro code, leaving the class name `toString` as the default. This would be preferred as Avro objects contained within other objects will be output with their class names when turned into strings, which does not happen with the previous option.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)