以下是我用于以 JSON 形式返回模型列表的方法
@RequestMapping(value = "/fetchAddress.htm", method = RequestMethod.GET)
@ResponseBody
public GenericEntity<List<Address>> fetchAddress(@RequestParam(value="addressId", required=true) int addressId){
logger.debug("fetchQueryDetails called");
List<Address> al =queryDao.fetchAddress(addressId);
GenericEntity<List<Address>> gal= new GenericEntity<List<Address>>(al){};
return gal;
}
}
以下是我的模型课
@XmlRootElement(name = "Address")
@XmlAccessorType(XmlAccessType.FIELD)
public class AddressImpl implements Address {
properties, setter, getter.
}
以下是我得到的 JSON 响应
{"rawType":"java.util.ArrayList","type":{"actualTypeArguments":["com.mvp.Address"],"rawType":"java.util.List","ownerType":null},"entity":[{"flatno":"S-2","houseNo":"42","street":"mother dairy","sector":"sec-2A","city":"kashi","state":"U.P.","country":"India","pin":"200001"},{"flatno":"S-2222222","houseNo":"42","street":"mother dairrrrrrrry","sector":"sec-2AAaa","city":"varansi","state":"U.P.","country":"India","pin":"201101"}]}
现在在 JSON 响应中,我不希望输出中的 rawType、type、ownerType 以及实体名称被更改,例如 addressList。还有任何想法如何避免 bean 类的某些属性不出现在 JSON 中。我正在使用 Jackson 库来创建 JSON。以下是我正在使用的罐子。
jackson-mapper-asl-1.9.2.jar,
jackson-xc-1.9.2.jar,
jackson-jaxrs-1.9.2.jar,
jackson-core-asl-1.9.2.jar
有遇到同样情况的,求指教。
谢谢