vojtechhabarta / typescript-generator

Generates TypeScript from Java - JSON declarations, REST service client

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling common record properties in Java interfaces

lpandzic opened this issue · comments

Is there a way, similar to java bean classes and interfaces, to have typescript generator generate properties for interfaces over java records?

Java Bean example:

public class A implements I {
    private final String b;
    
    ... constructor and getter
}

public interface I {
    String getB();
}

Generated typescript:

interface I {
    b: string
}

However, if I apply similar pattern to java records it doesn't work:

public record A (String b) implements I {
}

public interface I {
    String b();
}

Generated typescript:

interface I {
}

Is this use case supported by some mechanism?

After remembering that typescript generator uses jackson under the hood to detect properties the solution was evident:

public record A (String b) implements I {
}

public interface I {
    @JsonGetter
    String b();
}

Generated typescript:

interface I {
     b: string
}