Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is more a clarification request than an issue #4

Open
navy1978 opened this issue Jan 9, 2020 · 3 comments
Open

This is more a clarification request than an issue #4

navy1978 opened this issue Jan 9, 2020 · 3 comments

Comments

@navy1978
Copy link

navy1978 commented Jan 9, 2020

How can I add annotation to the ts files?
I need to use an Angular library (angular2-jsonapi) that needs class and fileds to be annotated with a specific annotation. Like the following:
`import { JsonApiModelConfig, JsonApiModel, Attribute, HasMany, BelongsTo } from 'angular2-jsonapi';

@JsonApiModelConfig({
type: 'examples',

})
export class Example extends JsonApiModel {
@Attribute()
id: string;

@Attribute()
title: string;`

I was thinking to add a special annotation in Java and get what I want in ts. But not clear to me how to proceed.

First of all : Is possible to accomplish that with your library?
Do we need to implement a special Converter, right?

I'm thinking to put some extra logic in a custom: "ModelClassesAbstractConverter"
and in the method: "getClassProperties" check if my JavaClass contain a special(custom) annotation @MyAnnotation like this:

if (javaClass.isAnnotationPresent(MyAnnotation.class)) { System.out.println("Found annotation in the class!"); }

if (field.isAnnotationPresent(MyAnnotation.class)) { System.out.println("Found annoatation in the field") }
But I don't see some special setting in the Property class that can be used later on to add the annotation into the ts file...
Can you please provide an example?

Thank you in advance.

@navy1978 navy1978 changed the title More than issue is a clarification request This is more a clarification request than an issue Jan 9, 2020
@tomasz-wozniak75
Copy link
Contributor

Hi
I will look on angular2-jsonapi library and I will let you know on Monday
thanks for interest in this project
Tomek

@tomasz-wozniak75
Copy link
Contributor

tomasz-wozniak75 commented Jan 11, 2020

Hi
"First of all : Is possible to accomplish that with your library?"
YES :) please checkout branch "version-1.2.4-angular2-jsonapi" I created for You new converter ModelClassesToTsAngular2JsonApiConverter which do already most of the job, please run it in example Angular2JsonApiTest

You was right, new converter was needed

Property is a mean to collect java field and methods which have impact on TypeScript field. In jackson/fasterxml You can make crazy things with mapping java field and getters/setters to JSON field
So java annotations are on java field or getter or setter which are kept by Property class instance. Please look at ModelClassesToTsAngular2JsonApiConverter.addAngular2JsonApiDecorators in this method I'm adding Decorators to TS field and it seems that You don't need any java annotation for it except JsonApiModelConfig where field "type" value must be set, now I'm generating such value, so for this purpose I will add class level annotations and from this annotation set TS decorator value (method createJsonApiModelConfigDecorator)

I'm new to angular2-jsonapi I don't know if you need to generate only model or some controller proxies are also required, please feel free to develop in branch "version-1.2.4-angular2-jsonapi" I would like to help You achieve proper implementation.

You can reach me on skype tomaszwozniak@interia.pl
Tomek

@navy1978
Copy link
Author

Thank you very much, I'm going to give it a try... And I will add you on skype ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants