2013-10-23 2 views
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 annotaion을 부여하지만, 그것은 IllegealannotationexceptionJAXB Unmarshaller에 판독 값은 0

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 
+1

을 앞으로 코드를 포맷하고 편집기에 코드를 붙여 넣을 때 코드 ('{}') 버튼을 사용하십시오. XML과 바인딩 된 클래스를 보지 않고도 추측을 제외하고는 할 수있는 일이 많지 않습니다. 그것은 우리 시간과 당신의 낭비입니다. –

답변

0

XML 문서가 일치하지 않는 경우 null 될 것입니다 비 정렬 화되는 값에 대한 예외를 throw로 매핑. 가장 쉬운 방법은 객체 모델을 채운 다음 마샬링하여 현재 매핑에 해당하는 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