0

When I use custom enum in the crunch parallelDo (Avros.reflects(TestEnumType.class)) map function, I am getting the below error.

Error: org.apache.crunch.CrunchRuntimeException: java.lang.NoSuchMethodException:EntityChangeType.<init>() at org.apache.crunch.types.avro.AvroDeepCopier$AvroReflectDeepCopier.createNewInstance(AvroDeepCopier.java:157)

Once I change the enum to class, Avro serialization works fine. In both enum and class, I have no argument constructor, and the class is declared static. How do I serialize the enums using Avros.reflects method?

The enum that doesn't work:

public static enum EntityChangeType {
    Field1,
    Field2,
    Field3;
   EntityChangeType() {}
}

After representing the same enum to the class it works:

 public static class EntityChangeType {
    private final String entityChangeStatus;
    public EntityChangeType() {
      this(new String("Field1"));
    }

    public EntityChangeType(String entityChangeStatus) {
     this.entityChangeStatus = entityChangeStatus;
     }

    public String toString() {
      return this.entityChangeStatus;
    }

    public static final EntityChangeType FIELD1 = new EntityChangeType("Field1");
    public static final EntityChangeType FIELD2 = new EntityChangeType("Field2");
    public static final EntityChangeType FIELD3 = new EntityChangeType("Field3");
}
Shravan Ramamurthy
  • 3,896
  • 5
  • 30
  • 44

0 Answers0