hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Add support for @JsonIgnoreProperties in the endpoint type generator

Open vlukashov opened this issue 5 years ago • 1 comments
trafficstars

When using typed endpoints and auto-generated TypeScript types, I expect that adding a @JsonIgnoreProperties annotation on a Java type or one of its properties not only excludes the listed properties from the JSON sent to the browser, but also excludes these properties from the corresponding TypeScript type, so that the generated TypeScript types correctly describe the runtime values.

1. @JsonIgnoreProperties on a bean property

public class Contact {
    private String email;

    @JsonIgnoreProperties("employees")
    private Company company;
}

public class Company {
  private String name;
  private List<Contact> employees;
}

Expected TypeScript types

export default interface Contact {
  company: Omit<Company, 'employees'>;
  email: string;
}

export default interface Company {
  employees: Array<Contact>;
  name: string;
}

2. @JsonIgnoreProperties on a class NOTE: this is an equivalent to adding @JsonIgnore on each of the listed properties.

@JsonIgnoreProperties("employees")
public class Company {
  private String name;
  private List<Contact> employees;
}

Expected TypeScript types

export default interface Company {
  name: string;
}

vlukashov avatar Oct 12 '20 20:10 vlukashov

State of this is a bit confusing, as it is already included in the documentation, but looks like not implemented yet https://vaadin.com/docs/latest/fusion/advanced/custom-serialization

TatuLund avatar Feb 01 '22 06:02 TatuLund