gpt4 book ai didi

java - Resteasy POST 未找到合适的构造函数

转载 作者:行者123 更新时间:2023-12-01 13:11:25 25 4
gpt4 key购买 nike

我有一个 RestEasy 休息 Web 服务,我在其中发布带有一些数据的 json,并且该方法有一个对象作为参数来反射(reflect)发布的数据,但出现以下异常:

org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class si.arctur.webservices.OrganizationWS$OrganizationWrapper]: can not instantiate from JSON object (need to add/enable type infmation?)

构造函数已定义,找不到合适的构造函数,找不到原因?

我的代码是:

@POST
@Consumes("application/json")
@Produces("application/json")
public Response createNewOrganization(OrganizationWrapper organization) {

.........
}

对象:

 public class OrganizationWrapper implements java.io.Serializable {

private static final long serialVersionUID = 5931983940786473663L;

private String idOrganization = "";
private String name= "";
private String address= "";
private String zipId= "";
private String zipName= "";
private String province= "";
private String country= "";
private String registerNum= "";
private boolean taxObligation = false;
private String taxNumber= "";
private String phoneNum= "";
private String faxNum= "";
private String email= "";
private String webPage= "";


public OrganizationWrapper(){}

public OrganizationWrapper(String idOrganization){
this.idOrganization = idOrganization;
}

public OrganizationWrapper(String idOrganization, String name,
String address, String zipId, String zipName, String province,
String country, String registerNum, boolean taxObligation,
String taxNumber, String phoneNum, String faxNum, String eMail,
String webPage) {
this.idOrganization = idOrganization;
this.name = name;
this.address = address;
this.zipId = zipId;
this.zipName = zipName;
this.province = province;
this.country = country;
this.registerNum = registerNum;
this.taxObligation = taxObligation;
this.taxNumber = taxNumber;
this.phoneNum = phoneNum;
this.faxNum = faxNum;
this.email = eMail;
this.webPage = webPage;
}

public String getIdOrganization() {
return idOrganization;
}
public void setIdOrganization(String idOrganization) {
this.idOrganization = idOrganization;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getZipId() {
return zipId;
}
public void setZipId(String zipId) {
this.zipId = zipId;
}
public String getZipName() {
return zipName;
}
public void setZipName(String zipName) {
this.zipName = zipName;
}
public String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getRegisterNum() {
return registerNum;
}
public void setRegisterNum(String registerNum) {
this.registerNum = registerNum;
}
public boolean isTaxObligation() {
return taxObligation;
}
public void setTaxObligation(boolean taxObligation) {
this.taxObligation = taxObligation;
}
public String getTaxNumber() {
return taxNumber;
}
public void setTaxNumber(String taxNumber) {
this.taxNumber = taxNumber;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
public String getFaxNum() {
return faxNum;
}
public void setFaxNum(String faxNum) {
this.faxNum = faxNum;
}
public String getEMail() {
return this.email;
}
public void setEMail(String eMail) {
this.email = eMail;
}
public String getWebPage() {
return webPage;
}
public void setWebPage(String webPage) {
this.webPage = webPage;
}




}

json数据:

  {"idOrganization":"2005032113214816","name":"Arctur d.o.o.","address":"Industrijska cesta 5","zipId":"5000","zipName":"Nova Gorica","province":"","country":"SI","registerNum":"5562325","taxObligation":true,"taxNumber":"76530566","phoneNum":"+386.53029070","faxNum":"+386.53022042","email":"info@arctur.si","webPage":""}

最佳答案

我已经找到了解决方案,问题是 OrganizationWrapper 是与 webservice 定义在同一类中的内部类。当我将类移到 webservice 类之外时,它开始工作。不知道其原因,但它现在对我有用。

关于java - Resteasy POST 未找到合适的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22832263/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com