JAXBContext jaxbContext = JAXBContext.newInstance(BatchwisePricingJob.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(batchprice.toString());
BatchwisePricingJob batch = (BatchwisePricingJob) jaxbUnmarshaller.unmarshal(reader);
ArrayList<Price> pricingOfProduct = batch.getPricingOfProduct();
int i = 0;
for (Price price : pricingOfProduct) {
i++;
System.out.println("customer id:" + i + " " + price.getCustomerId());
System.out.println("material id:" + i + " " + price.getMaterialId());
}
还为getter / setter提供了@XmlElement
注释,但随后它会抛出Illegealannotationexception
Class has two properties of the same name "customerId"
this problem is related to the following location:
at public int com.efl.efms.batch.ws.data.batchwisePricing.Price.getCustomerId()
at com.efl.efms.batch.ws.data.batchwisePricing.Price
at private java.util.ArrayList com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob.pricingOfProduct
at com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob
this problem is related to the following location:
at private int com.efl.efms.batch.ws.data.batchwisePricing.Price.customerId
at com.efl.efms.batch.ws.data.batchwisePricing.Price
at private java.util.ArrayList com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob.pricingOfProduct
at com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob
答案 0 :(得分:0)
如果XML文档与您的映射不匹配,则解组的值将为null
。最简单的方法是填充对象模型,然后将其编组,以查看与当前映射对应的XML。如果所需的名称与默认值不同,您可以使用@XmlElement
和@XmlAttribute
指定要映射到的名称。
如果映射字段及其对应的属性,您将看到以下异常。以下文章将为您提供帮助:http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
Class has two properties of the same name "customerId"
this problem is related to the following location:
at public int com.efl.efms.batch.ws.data.batchwisePricing.Price.getCustomerId()
at com.efl.efms.batch.ws.data.batchwisePricing.Price
at private java.util.ArrayList com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob.pricingOfProduct
at com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob
this problem is related to the following location:
at private int com.efl.efms.batch.ws.data.batchwisePricing.Price.customerId
at com.efl.efms.batch.ws.data.batchwisePricing.Price
at private java.util.ArrayList com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob.pricingOfProduct
at com.efl.efms.batch.ws.data.batchwisePricing.BatchwisePricingJob