Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAX-RS/Jersey:java.lang.ClassCastException-无法转换为javax.xml.bind.JAXBElement_Java_Web Services_Jersey_Jax Rs - Fatal编程技术网

JAX-RS/Jersey:java.lang.ClassCastException-无法转换为javax.xml.bind.JAXBElement

JAX-RS/Jersey:java.lang.ClassCastException-无法转换为javax.xml.bind.JAXBElement,java,web-services,jersey,jax-rs,Java,Web Services,Jersey,Jax Rs,我将应用程序分为前端和后端模块,它们通过restfull Web服务进行通信。不幸的是,这段代码出现了一些错误,我从后端部分得到: java.lang.ClassCastException: com.rrd.ecomdd.data.SharedFile cannot be cast to javax.xml.bind.JAXBElement 前端代码段: @Override public void share(Set<SharedFile> fileSet) { apiT

我将应用程序分为前端和后端模块,它们通过restfull Web服务进行通信。不幸的是,这段代码出现了一些错误,我从后端部分得到:

java.lang.ClassCastException: com.rrd.ecomdd.data.SharedFile cannot be cast to javax.xml.bind.JAXBElement 
前端代码段:

@Override
public void share(Set<SharedFile> fileSet) {
    apiTarget.path(ApiConstant.FILESERVICE)
            .path(ApiConstant.FILESERVICE_SHARE)
            .request(MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8"))
            .post(Entity.entity(fileSet.toArray(new SharedFile[0]), MediaType.APPLICATION_JSON_TYPE.withCharset("UTF-8")), new GenericType<Set<SharedFile>>() {
            });
}

有什么办法可以解决这个问题吗?

试着对类及其属性进行注释,如下所述:

@XmlRootElement
public class SharedFile {

  @XmlElement
  private Long id;

  @XmlElement
  private User user;

  @XmlElement
  private ManagedFile file;
请遵循以下步骤了解更多信息:

public class SharedFile {

  private Long id;
  private User user;
  private ManagedFile file;
  private UUID uuid = UUID.randomUUID();

  public SharedFile(User user, ManagedFile file) {
    this.user = user;
    this.file = file;
  }

  public SharedFile() {
  }
  //getters, setters, equals and hashcode below

}
@XmlRootElement
public class SharedFile {

  @XmlElement
  private Long id;

  @XmlElement
  private User user;

  @XmlElement
  private ManagedFile file;