Generate TypeScript interfaces from Java Classes
Why spend time writing interfaces when you can enjoy a cup of afternoon flat white instead?
Published in
4 min readMar 14, 2022
I believe we can all agree that the benefit of code generation is tremendous, as it automates some of the repetitive or mundane tasks for us, so that we can spend our time on the actual technical challenges.
In this scenario, the obvious benefits of generating typescript from java are:
- Eliminating concerns and extra effort to maintain object/interface consistency between backend and frontend codebases.
- Time saving (of course).
Enough said, let’s jump right in.
Setup
Step 1, add the following dependencies in your pom.xml
What we need to take note here is the field classPatterns, which indicates that we want to generate Typescript interfaces for all qualified Java classes in this package.
Let’s assume all our targets are located in the package com.test.generator
.
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.1</version>…