1
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());
}

@XmlElement为 getter/setter 提供了注释,但随后它引发了异常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
4

1 回答 1

0

null如果 XML 文档与您的映射不匹配,则将被解组的值。最简单的做法是填充对象模型,然后将其编组以查看与当前映射对应的 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
于 2013-10-23T13:51:20.350 回答