vertx-codegen icon indicating copy to clipboard operation
vertx-codegen copied to clipboard

enum custom Marshalling/Unmarshalling

Open alexmig17 opened this issue 7 years ago • 4 comments

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.

alexmig17 avatar May 08 '18 17:05 alexmig17

why do you need such marshalling ? for service proxies ?

vietj avatar May 08 '18 19:05 vietj

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

alexmig17 avatar Aug 28 '18 13:08 alexmig17

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.

aygalinc avatar Jan 08 '19 09:01 aygalinc

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;
  }
}

jacobhampel avatar Mar 26 '19 07:03 jacobhampel