gpt4 book ai didi

java - jaxb 解码器将值读取为 0

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

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 注释,但随后它抛出了 Illegalannotationexceptions

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

最佳答案

如果 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

关于java - jaxb 解码器将值读取为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19543061/

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