You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "Ryan Blue (JIRA)" <ji...@apache.org> on 2013/11/06 19:26:18 UTC

[jira] [Commented] (AVRO-1392) Unable to marshal enum to Avro

    [ https://issues.apache.org/jira/browse/AVRO-1392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13815116#comment-13815116 ] 

Ryan Blue commented on AVRO-1392:
---------------------------------

If you could post a stack trace of the problem, it would be easier to help troubleshoot.

In the mean time, It looks like you're telling Avro to encode the enums, {{UserTypeEnum}} and {{ApplicationEnum}} as strings by annotating them with {{@Stringable}}. But when it goes to set those fields, they aren't assignable from strings. A work-around you may want to try is to add getters/setters that translate:

{code:java}
protected String userType;

public void setUserType(UserTypeEnum e) {
  this.userType = e.toString();
}

public UserTypeEnum getUserType() {
  return UserTypeEnum.valueOf(userType);
}
{code}

Another method that is probably better is to use {{@AvroEncode}} that correctly translates to/from an Avro enum and your enum class. I don't see a way in the docs (e.g., and @Enum annotation) to set the type if the field is serialized as an enum, so it will probably default to {{GenericEnumSymbol}}.

> Unable to marshal enum to Avro
> ------------------------------
>
>                 Key: AVRO-1392
>                 URL: https://issues.apache.org/jira/browse/AVRO-1392
>             Project: Avro
>          Issue Type: Bug
>          Components: java
>         Environment: DEV
>            Reporter: Balaji Seshadri
>            Priority: Blocker
>
> I'm trying to marshall below object to Avro format and unable to marshall it using ReflectDatum Writer.Enums are being rejected while marshalling.
> {code:java}
> public class AccountAccess extends DESBusinessEvent<String> {
>     @XmlElement(required = true)
>     protected String accountId;
>     @XmlElement(required = true)
>     @XmlSchemaType(name = "dateTime")
>     @AvroEncode(using=XmlDateAsLong.class)
>     protected XMLGregorianCalendar dateTime;
> //    @XmlElement(namespace = DESNamespaces.ENUM_NAMESPACE, required = true)
>     @XmlElement(required = true)
>     @Stringable
>     protected ApplicationEnum application;
> //    @XmlElement(namespace = DESNamespaces.ENUM_NAMESPACE, required = true)
>     @XmlElement(required = true)
>     @Stringable
>     protected UserTypeEnum userType;
>     protected String userId;
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.1#6144)