public class CustomerAddress {
private Customer customer;
//I think the problem is in hear becouse jackson does not know how to serialize this object list
private List<Address> address;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public List<Address> getAddress() {
return address;
}
public void setAddress(List<Address> address) {
this.address = address;
}
}
public class Address{
private Integer id;
private Customer customer;
private AddressType addressType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public AddressType getAddressType() {
return addressType;
}
public void setAddressType(AddressType addressType) {
this.addressType = addressType;
}
}
public class Customer {
private Integer id;
private String firstName;
private String middleName;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
}
我从 DB 表单中获取数据,并像这样将其发送回页面
CustomerAddress customerAddress = customerAddressService.getCustomerAddress(22);
Map<String, Object> map = getMapCustomerAddress(customerAddress);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
return mapper.writeValueAsString(map);
这是我返回地图的方法
private Map<String, Object> getMapCustomerAddress(CustomerAddress customerAddress) throws IOException {
Map<String, Object> modelMap = new HashMap<String, Object>(3);
modelMap.put("total", 1);
modelMap.put("data", customerAddress);
modelMap.put("success", true);
return modelMap;
}
我得到的错误
java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException$Reference
com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:613)
com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:142)
任何人都可以告诉我如何使用杰克逊将这个“CustomerAddress”类转换为json