Skip to content
This repository has been archived by the owner on Nov 22, 2021. It is now read-only.

Latest commit

 

History

History
84 lines (65 loc) · 3.28 KB

README.md

File metadata and controls

84 lines (65 loc) · 3.28 KB

Java to TypeScript (Maven plugin)

Libraries.io dependency status for GitHub repo Snyk Vulnerabilities for GitHub Repo

Codacy Badge codecov

GitHub Actions

Maven Central Javadocs

Generate your TypeScript DTO classes from Java DTO classes.

Example

Java DTO class: src/main/java/fr/pinguet62/java2typescript/sample/dto/MyDto.java

package fr.pinguet62.java2typescript.sample.dto;

import java.util.List;
import fr.pinguet62.java2typescript.sample.dto.sub.OtherDto;

public class MyDto {
    private int id;
    private List<String> codes;
    private OtherDto other;
    // getter & setter
}

Maven plugin:

<plugin>
    <groupId>com.github.pinguet62</groupId>
    <artifactId>java2typescript-maven-plugin</artifactId>
    <version>...</version>
    <configuration>
        <srcDir>src/main/java/fr/pinguet62/java2typescript/sample/dto/</srcDir>
        <tgtDir>src/main/webapp/app/dto/</tgtDir>
    </configuration>
</plugin>

Output: src/main/webapp/app/dto/MyDto.ts

import {OtherDto} from './sub/OtherDto';

export class MyDto {
    id: number;
    codes: Array<string>;
    other: OtherDto;
}

Configuration

  • srcDir
    The Java DTO source folder
    • Required: true
    • Command line argument: java2typescript.srcDir (ex: mvn ... -Djava2typescript.srcDir=...)
  • tgtDir
    The TypeScript DTO target folder (created if doesn't exist)
    • Required: true
    • Command line argument: java2typescript.tgtDir (ex: mvn ... -Djava2typescript.tgtDir=...)

Limitations

Supported

  • Generic types
  • Dependency (but not checked)

Not (yet) supported

  • Merge: generated file replace old
  • Methods: only attributes are parsed
  • Included classes & multi-classes: only 1 public class per file
  • Attribute initialization: convert only declarations
  • Advanced primitive types: Map is not supported
  • JSON field name using @annotation
  • Multi-configuration: if you have several DTO packages
  • File path/name pattern: actually {srcDir}/**Dto.java