/j2s

java to typescript library

Primary LanguageJava

The library is designed to create a single dialect of communication between Spring and Angular on the Spring side of the application.

Typically, communication between Spring and Angular occurs using DTO objects, copies of which are created for each side separately. This means that if we want to modify or add a DTO, we have to do it twice, on two sides and in two different programming languages. The library provides the ability to have only one set of these DTOs on the Spring side of the application. They will be automatically converted to TypeScript on build and published to the repository. An Angular application only needs to sync the library from the repository.

Example java object:

@J2SLibrary(name = "my-awesome-user-library")
@J2SModel
public class User {
    private String firstname;
    private String lastname;
    private int age;
    
    private Role[] roles;
}

@J2SModel
public class Role {
    private String name;
    private int id;
}

The same object generated by the J2S on TypeScript:

import { Role } from "./Role";

export class User {
    firstname: string;
    lastname: string;
    age: number;
    roles: Role[]
}

export class Role {
    name: string;
    id: number;
}

Usage:

Customize pom.xml of your project with the following part:

    <dependencies>
        <dependency>
            <groupId>org.j2s</groupId>
            <artifactId>j2s-core</artifactId>
            <version>0.0.1</version>
        </dependency>
        <dependency>
            <groupId>org.j2s</groupId>
            <artifactId>j2s-maven-plugin</artifactId>
            <version>0.0.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.j2s</groupId>
                <artifactId>j2s-maven-plugin</artifactId>
                <version>0.0.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>j2s-mojo</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

todo:

  • repair the J2SLibPublisher. it does not publish libraries to the repo. throws an 400 bad request error. try to npm login
  • junit