0

I'm pretty sure that I'm missing something obvious here, but for some reason I keep getting the 'java.lang.annotation.AnnotationTypeMismatchException' error when I try to run the 'mvn jsondoc:generate -X' command.

The full error is shown below:

java.lang.annotation.AnnotationTypeMismatchException: Incorrectly typed data found for annotation element public abstract java.lang.String[] org.jsondoc.core.annotation.ApiMethod.path() (Found data of type class java.lang.String[/users/{jsonRepresentation}])
 at sun.reflect.annotation.AnnotationTypeMismatchExceptionProxy.generateException(AnnotationTypeMismatchExceptionProxy.java:57)
 at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:83)
 at com.sun.proxy.$Proxy25.path(Unknown Source)
 at org.jsondoc.core.scanner.builder.JSONDocApiMethodDocBuilder.build(JSONDocApiMethodDocBuilder.java:22)
 at org.jsondoc.core.scanner.DefaultJSONDocScanner.initApiMethodDoc(DefaultJSONDocScanner.java:68)
 at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiMethodDoc(AbstractJSONDocScanner.java:163)
 at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiMethodDocs(AbstractJSONDocScanner.java:154)
 at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiDoc(AbstractJSONDocScanner.java:141)
 at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiDocs(AbstractJSONDocScanner.java:124)
 at org.jsondoc.core.scanner.AbstractJSONDocScanner.getApiDocsMap(AbstractJSONDocScanner.java:222)
 at org.jsondoc.core.scanner.AbstractJSONDocScanner.getJSONDoc(AbstractJSONDocScanner.java:106)
 at org.jsondoc.JSONDocMojo.execute(JSONDocMojo.java:100)
 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
 at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
 at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
 at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
 at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
 at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
 at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
 at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

I don't understand this part of the error:

'Incorrectly typed data found for annotation element public abstract java.lang.String[] org.jsondoc.core.annotation.ApiMethod.path()'

Because according to the documentation(http://jsondoc.org/annotations.html#apimethod) the 'path' should be a String and not a String[]? So it kind of got me confused.

And my 'UserResource' class looks like this:

@Api(name="User Resource", description = "Resource for user Login")
public class UserResource extends ServerResource {

    @ApiMethod(
            path = "/users/{jsonRepresentation}",
            description = "test",
            produces = { "application/*+json" },
            consumes = { "application/*+json" },
            verb=ApiVerb.POST)

    @ApiErrors(apierrors = { @ApiError(code = "3000", description = "City already existing"), @ApiError(code = "9000", description = "Illegal argument") })
    @Post("json")
    public @ApiResponseObject Representation login(@ApiParam(name="jsonRepresentation", paramType = ApiParamType.PATH) JsonRepresentation jsonRepresentation) {

        Representation representation = null;

        try {
            JSONObject jsonObject = jsonRepresentation.getJsonObject();

            String username = jsonObject.getString("username");
            String password = jsonObject.getString("password");

            if (username.equals("test") && password.equals("test")) {
                User foundUser = new User();

                foundUser.setEmail("testEmail@email.com");
                foundUser.setPassword("testPassword");
                foundUser.setUsername("testUsername");

                representation = new JacksonRepresentation<User>(foundUser);
            } else {
                representation = new JacksonRepresentation<Status>(Status.CLIENT_ERROR_UNAUTHORIZED);
            }

        } catch (JSONException jsonException) {

        }

        return representation;
    }
}

I've been working on this for a few hours now and I'm kind of lost, I'm not sure what I'm doing wrong here. I'm pretty sure it has to do with the @ApiMethod, because I've also generated the documentation without the @ApiMethod and it seemed to work fine.

Oh, and my pom.xml contains this:

 <build>
        <pluginManagement>
            <plugins>
              <plugin>
                    <groupId>org.jsondoc</groupId>
                    <artifactId>jsondoc-maven-plugin</artifactId>
                    <version>1.2.9</version>
                    <configuration>
                        <version>1.1</version>
                        <basePath>http://localhost:8182</basePath>
                        <packages>
                            <package>com.quieazy.api</package>
                            <package>org.jsondoc.sample.controller</package>
                            <package>org.jsondoc.sample.pojo</package>
                        </packages>
                        <outputFile>/tmp/jsondoc.json</outputFile>
                        <scanner>org.jsondoc.core.scanner.DefaultJSONDocScanner</scanner>
                        <playgroundEnabled>true</playgroundEnabled> <!-- optional -->
                        <displayMethodAs>URI</displayMethodAs> <!-- optional -->
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

Maybe there is something wrong with my pom.xml settings?

Thanks in advance.

0 Answers0