eclipse-vertx / vertx-codegen

Vert.x code generator for asynchronous polyglot APIs
Apache License 2.0
108 stars 92 forks source link

enum custom Marshalling/Unmarshalling #174

Open alexmig17 opened 6 years ago

alexmig17 commented 6 years ago

How can I do custom Marshalling/Unmarshalling for JAVA enum for now vertx-codegen is used standard name() and valueOf() methods for example jackson has @JsonCreator and @JsonValue for this case.

vietj commented 6 years ago

why do you need such marshalling ? for service proxies ?

alexmig17 commented 6 years ago

I can see it is still open. Sorry for delay. Our application is used vert-x event bus for communicate between inner micro services. But outer services based on rest. We want to use vertx-codegen converter for event bus and rest. For rest we have contract for enums - just first letter should be in upper case. Like result - standard Marshalling/Unmarshalling doesn't fit

aygalinc commented 5 years ago

Hi,

I have a use case where an event bus service can be invoked from a Rest endpoint or from local event bus consumer. So this service take a sort of request which is a placeholder for several parameters (String, enum, etc ...). I can overide toString method to fit my needs in marshalling but i cannot override valueOf because it is static. So i cannot benefit of all the power of vertx code generation in this case.

jacobhampel commented 5 years ago

Hi, I see also another issue with the current implementation. If the expected value is an Integer the name of the Enum can't match its expected value. E.g.

public enum IntegerEnum {
  _16(16),
  _20(20);

  private int value;
  IntegerEnum(int value) 
  {
    return value;
  }
}