[ 
https://issues.apache.org/jira/browse/AVRO-3164?focusedWorklogId=703934&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-703934
 ]

ASF GitHub Bot logged work on AVRO-3164:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Jan/22 13:25
            Start Date: 05/Jan/22 13:25
    Worklog Time Spent: 10m 
      Work Description: opwvhk commented on a change in pull request #1277:
URL: https://github.com/apache/avro/pull/1277#discussion_r778815057



##########
File path: 
lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
##########
@@ -855,3 +856,23 @@ $I    } else {
 #set ($I = $this.indent($indent))
 $I    }
 #end
+
+#macro( assignField $field $schema)
+#set($I = $this.indent(6))
+#if ($this.shouldBeDeserializedFromString($field.schema()))
+#if ($this.constructorThrowsCheckedException($field.schema()))
+$I  try {
+#end
+$I  if (null != value$) {
+$I    ${this.mangle($field.name(), $schema.isError())} = new 
${this.javaType($field.schema())}(value$.toString());
+$I  }
+#if ($this.constructorThrowsCheckedException($field.schema()))
+$I  } catch (java.lang.Exception e) {
+$I    throw new org.apache.avro.AvroRuntimeException(e);
+$I  }
+#end
+#else
+$I  ${this.mangle($field.name(), $schema.isError())} = 
#if(${this.javaType($field.schema())} != "java.lang.Object" && 
${this.javaType($field.schema())} != 
"java.lang.String")(${this.javaType($field.schema())})#{end}value$#if(${this.javaType($field.schema())}
 == "java.lang.String") != null ? value$.toString() : null#{end};

Review comment:
       Thank you for the verbatim copy of the original code; that makes reading 
the change a lot easier.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 703934)
    Time Spent: 20m  (was: 10m)

> Allow stringable types deserialization if java-class is specified
> -----------------------------------------------------------------
>
>                 Key: AVRO-3164
>                 URL: https://issues.apache.org/jira/browse/AVRO-3164
>             Project: Apache Avro
>          Issue Type: New Feature
>          Components: java
>            Reporter: Artur Kalimullin
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Currently, compiler supports java-class and generates java classes with the 
> given class. It works properly with serialization as toString() is being 
> called, however, on deserialization compiler generates casting instead of 
> calling a constructor with the string argument.
> It works with the ReflectData but not with the SpecificData which throws 
> ClassCastException in runtime.
> To solve this, the same behaviour as ReflectData could be used (calling a 
> constructor with a String argument)
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to