0

I ran into this problem when trying to bind a combo-box to my model. The enum values are null when they are submitted to my endpoint class in the backend.

<vaadin-combo-box label="identifier type" id="identifier_type"
    ${field(this.binder.model.entity.identification.idType)}
    .items="${Object.values(KeyType)}">
</vaadin-combo-box>

The Java enum looks like this:

public enum KeyType {
  CUSTOM("Custom"),
  IRDI("IRDI"),
  IRI("IRI"),
  IDSHORT("IdShort"),
  FRAGMENTID("FragmentId");
  ...
}

But the generated ts enum looks like this:

enum KeyType {
  CUSTOM = 'CUSTOM',
  IRDI = 'IRDI',
  IRI = 'IRI',
  IDSHORT = 'IDSHORT',
  FRAGMENTID = 'FRAGMENTID',
}

All values are changed to uppercase, which is why the binder fails to match the ones which have camel case writing, which results in a null value for the field.

Can this be configured, is this by design, or is this a bug?

Thanks&BR Daniel

ollitietavainen
  • 3,900
  • 13
  • 30
Daniel
  • 117
  • 1
  • 11
  • For code generation Fusion uses the actual names of the enum values (FRAGMENTID), not the string values you pass into the constructor ("FragmentId"). After all the parameter you pass to the constructor could be any type (for example a boolean), it might not be unique, and there could be multiple of them. Apart from that your code looks fine, and I can not reproduce your issue with the values not being correctly mapped. – Sascha Ißbrücker Nov 05 '21 at 11:08
  • I "fixed it" now by putting an equalsIgnoreCase instead of equals in the @JsonCreator fromValue method of the KeyType class. – Daniel Nov 08 '21 at 12:18

1 Answers1

1

It is not like values are changed to uppercase. The Fusion generator just uses the enum element names for both key and value ignoring any data in parenthesis. That is by design and for now, there are no plans to change this behavior.

The reason here is that TypeScript enums are way less powerful than Java's. For example, you send a string as an enum element value; but what if it is an object? The TS enumeration cannot reflect that change, so the Fusion generator cannot do it either.

Though there are no plans for changing the built-in behavior, in the future the Fusion generator is going to be more flexible, so you will be able to tweak it to support your case.

Lodin
  • 2,028
  • 2
  • 18
  • 29