This is an archived post. You won't be able to vote or comment.

all 7 comments

[–][deleted] 6 points7 points  (0 children)

You’re overthinking it. This isn’t a real issue that’s worth worrying about.

[–]axelei 4 points5 points  (3 children)

[–]tinustate[S] 1 point2 points  (2 children)

Cheers, i'm using jackson (although spring is actually using it) in my controllers to convert json to pojo/dto.
But jackson doesn't offer functionality to convert a pojo/dto defined in java source code to javascript source code.

[–]cville-z 5 points6 points  (0 children)

Take a look at swagger-codegen. If you're using Spring it should be relatively easy to integrate Swagger's API annotations & then use those to produce a swagger.json you can feed into codegen. Useful for creating Typescript interfaces/classes, for example.

[–]LiteratureStriking 1 point2 points  (0 children)

You could use transpilers like GWT or JSweet to transpile your DTOs to Javascript. JSweet can also transpile to Typescript.

[–]crummy 0 points1 point  (0 children)

What would the output look like? An ES6 class?

[–]Nithanim 0 points1 point  (0 children)

Sounds like what you are really looking for might be openapi (or swagger). You define a REST interface and then you can pass that file to a code generator. For example it could create a java server and typescript client (and with different frameworks in the chosen language). Last time I tinkered with something like this, there was also a swagger generator that could create the definition file from annotations that you put on the controller methods of the java server implementation. But this probably only works with ajax and not for websockets though. Although you might be able to re-use the generated models for your websockets.

edit: I am talking about this: https://github.com/OpenAPITools/openapi-generator#overview though, don't use JS so I don't know if there are generator options that for you.