0

I'm hitting the error "No support yet for multidimensional arrays" when running docs goal for maven plugin enunciate. Is there a way I can avoid it bombing out the process (ie. generate the rest of the docs for the API)?

I've tried @org.codehaus.enunciate.doc.ExcludeFromDocumentation on the API method returning the class with double array. I've tried @org.codehaus.enunciate.XmlTransient on the class with the double array.

I have since seen in enunciate documentation where those only affect whether they display on docs, not compilation.

I'm happy to hear any ideas you have!

Thanks.

Edit: The best I could do was dump project to temp directory, rip out all modules that aren't necessary to reach the api, delete the class with double array, and replace that part of the REST api's java method signature with String. This allows me to at least create the api document page via enunciate and give a description via javadoc. But, I'd love to have a more elegant solution, so please share if you know of one :)

Edit 2: Example pom:

<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.company.services.rest.service</groupId>
 <artifactId>service-rest-api</artifactId>
 <packaging>pom</packaging>
 <version>1.1</version>
 <name>service  REST API</name>
 <dependencies>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxrs</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
      <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.2.4</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>jaxrs-api</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jackson-provider</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-jaxb-provider</artifactId>
        <version>2.2.1.GA</version>
        <exclusions>
          <exclusion>
            <groupId>com.sun.xml.bind</groupId>
            <artifactId>jaxb-impl</artifactId>
          </exclusion>
        </exclusions>
      </dependency>
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>resteasy-multipart-provider</artifactId>
        <version>2.2.1.GA</version>
      </dependency> 
      <dependency>
        <groupId>org.jboss.resteasy</groupId>
        <artifactId>tjws</artifactId>
        <version>2.2.1.GA</version>
      </dependency>
  </dependencies>
  <build>
    <plugins>
     <plugin>
       <groupId>org.codehaus.enunciate</groupId>
       <artifactId>maven-enunciate-plugin</artifactId>
       <version>1.26</version>
       <configuration>
         <forceWarPackaging>false</forceWarPackaging>
         <configFile>/tmp/enunciate-work/enunciate.xml</configFile>
       </configuration>
       <executions>
         <execution>
           <goals>
             <goal>docs</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
    </plugins>
  </build>

Files located src/main/java/com/company/services/user/rest:

package com.company.services.service.rest;

import javax.ws.rs.POST;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;

@Path("/")
public interface ServiceResource {
    @POST
    @Path("/statuschanges")
    @Produces({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
    @Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
    public ServiceStatusChanges getServiceStatusChangeLogs(String string);
}

package com.company.services.service.rest;

import java.io.Serializable;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class ServiceStatusChanges implements Serializable {
    private static final long serialVersionUID = 1l;
    private String[][] logs;
    public ServiceStatusChanges() {}

    public ServiceStatusChanges(String[][] logs) {
        this.logs=logs;
    }

    public String[][] getLogs() {
        return logs;
    }

    public void setLogs(String[][] logs) {
        this.logs=logs;
    }
}

enunciate.xml:

<enunciate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="
           http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">

  <modules>
      <disable-rule id="csharp.warnings"/>
      <disable-rule id="c.warnings"/>
      <disable-rule id="obj-c.warnings"/>
          <docs docsDir="api" title="REST API" includeDefaultDownloads="false" disableRestMountpoint="true">

    </docs>
    <!-- Disable all the client generation tools -->
    <basic-app disabled="true" />
    <c disabled="true" />
    <csharp disabled="true" />
    <java-client disabled="true" />
    <jaxws-client disabled="true" />
    <jaxws-ri disabled="false" />
    <jaxws-support disabled="false" />
    <jersey disabled="true" />
    <obj-c disabled="true" />
    <xml forceExampleJson="true"/>
    <jaxws disabled="false"/>
    <amf disabled="true"/>
  </modules>

</enunciate>
4

2 回答 2

0

当我使用List<String[]>type 而不是String[][]. 据我记得生成的 JSON/XML 示例和 xsd 似乎有问题。

于 2014-09-15T12:16:31.197 回答
0

如果您不需要该方法的 XML 支持,您可以在从 @Consumes 和 @Produces 中删除 MediaType.APPLICATION_XML 之后执行 JSON 并删除 @XmlRootElement 注释。

如果您仍然希望支持 XML,您可以进行一些增强以支持仅序列化更改,例如使logs属性 XML 瞬态并将数组包装为序列化时间。这将具有 Enunciate 能够记录它而不是一些带外文档的额外好处。例如:

@XmlRootElement
public class ServiceStatusChanges implements Serializable {
    private static final long serialVersionUID = 1l;
    private String[][] logs;
    public ServiceStatusChanges() {}

    public ServiceStatusChanges(String[][] logs) {
        this.logs=logs;
    }

    @XmlTransient
    public String[][] getLogs() {
        return logs;
    }

    public void setLogs(String[][] logs) {
        this.logs=logs;
    }

    @XmlElement( name = "logs" )
    public Log[] getLogsWrapped() {
        Log[] logs = new Log[this.logs.length];
        //iterate through the logs and wrap it...
        return logs;
    }
}

你的Log班级可能看起来像:

@XmlRootElement
public class Log implements Serializable {
    @XmlValue
    public String value;
}
于 2012-09-17T17:52:55.427 回答