javaflow icon indicating copy to clipboard operation
javaflow copied to clipboard

Include fields that only have getters

Open pascalgn opened this issue 6 years ago • 1 comments

Currently, the main focus for generated fields in types is the Java field. But consider the following Java class:

public class User {
    private String firstName;
    private String lastName;

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getName() {
        return firstName + " " + lastName;
    }
}

then usually (at least when using Jackson API), instances of that class will result in JSON like this:

{
  "firstName": "John",
  "lastName": "Smith",
  "name": "John Smith"
}

However, as there is no field name in class User, the resulting type will not include the name field:

export User = {
  firstName: string,
  lastName: string
};

pascalgn avatar Nov 11 '18 15:11 pascalgn

For simplicity (and because of the restraint on our Dto models) I implemented this using the fields, as the naming of the flowtype fields would be given without translation. But as you point out we should match Jackson in functionality and use the getters as a basis instead. Lets add a flag for selecting which you would want to use.

havardh avatar Nov 11 '18 17:11 havardh