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

Class doesn't have a Type annotation error, even though the class does have one #260

Open
dylwedma11748 opened this issue Mar 25, 2023 · 3 comments

Comments

@dylwedma11748
Copy link

dylwedma11748 commented Mar 25, 2023

My situation is a bit complicated. I'm working on a library to handle API calls to Patreon's APIv2 endpoints. I'm structuring my library similarly to the original. I've already wote most of the resource classes, but the error I'm getting is Class doesn't have a Type annotation. All resource classes must be annotated with a Type annotation! even though it does have one. I've uploaded all of the resource classes to a repo and I've also made a StackOverflow post explaining it in more detail.

The stacktrace I'm getting is:
Exception in thread "main" java.lang.IllegalArgumentException: Class [Lpatreon.java.v2.resources.Campaign; doesn't have a Type annotation. All resource classes must be annotated with a Type annotation! at com.github.jasminb.jsonapi.ConverterConfiguration.processClass(ConverterConfiguration.java:168) at com.github.jasminb.jsonapi.ConverterConfiguration.registerType(ConverterConfiguration.java:310) at com.github.jasminb.jsonapi.ConverterConfiguration.processClass(ConverterConfiguration.java:83) at com.github.jasminb.jsonapi.ConverterConfiguration.registerType(ConverterConfiguration.java:310) at com.github.jasminb.jsonapi.ConverterConfiguration.<init>(ConverterConfiguration.java:50) at com.github.jasminb.jsonapi.ResourceConverter.<init>(ResourceConverter.java:93) at com.github.jasminb.jsonapi.ResourceConverter.<init>(ResourceConverter.java:83) at patreon.java.v2.PatreonAPI.<init>(PatreonAPI.java:70) at patreon.java.v2.PatreonAPI.<init>(PatreonAPI.java:60) at patreon.java.v2.PatreonAPITest.main(PatreonAPITest.java:8)

The Campaign class does have a Type annotation:

@Type("campaign")
public class Campaign extends BaseResource {
    ...
}

The ResourceConverter is being initialized like so:

public class PatreonAPI {
    ...    
    private ResourceConverter converter;

    PatreonAPI(String accessToken, RequestUtil requestUtil) {
        this.accessToken = accessToken;
        this.requestUtil = requestUtil;

        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
        objectMapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        this.converter = new ResourceConverter(objectMapper, Address.class, Benefit.class, Campaign.class, Deliverable.class, Goal.class, Media.class, Member.class, PledgeEvent.class, Post.class, Tier.class, User.class);
        this.converter.enableDeserializationOption(DeserializationFeature.ALLOW_UNKNOWN_INCLUSIONS);
    }
}

I've found that at stack "ConverterConfiguration.processClass(Class<?>) line: 83", targetType is set to Campaign, but clazz is set to Address:

variables

In the Address class, the only reference to the Campaign class is an Array of Campaigns with a Relationship annotation:

@Type("address")
public class Address extends BaseResource {
    ...
    @Relationship("campaigns")
    private Campaign[] campaigns;
}
@jasminb
Copy link
Owner

jasminb commented Mar 25, 2023

Will take a look next week hopefully. Thank you for reporting!

@dylwedma11748
Copy link
Author

Not a problem. There's no rush, as this is a personal project.

@dylwedma11748
Copy link
Author

Found out that it was the arrays causing it, I guess for some reason when you use a resource class that has a Type annotation in an array, it doesn't work or something... I don't know. I replaced the arrays with Lists instead.

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