내 콩 클래스입니다 XML의 직렬화 복원시에 N/A : 여기이 JsonMappingException 해결 방법 : 다음
package request;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement
public class Employee {
private List<String> roles= new ArrayList<String>();
private String name;
public Employee(){}
@JacksonXmlProperty
public String getName()
{
return name;
}
public void setName (String name)
{
this.name = name;
}
@JacksonXmlElementWrapper(useWrapping=false)
@JacksonXmlProperty
public List<String> getRoles()
{
return roleCodes;
}
public void setRoles (String role)
{
this.roles.add(role);
}
}
하고,
package request;
import java.util.ArrayList;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
public class Employees
{
@JacksonXmlElementWrapper(localName="employees")
@JacksonXmlProperty(localName="employee")
private ArrayList<Employee> emps;
//Employee Employee ;
public Employees(){}
@JacksonXmlProperty(localName="employee")
public ArrayList<Employee> getEmployees()
{
return emps;
}
public void setEmployees(Employee emp){
this.emps.add(emp);
}
@Override
public String toString()
{
if(emps.isEmpty()!=true)
for (Employee e:emps)
return "this is [employee = "+e ;
return "none there";
}
public ArrayList<Employee> addingEmployee(Employee e){
this.emps.add(e);
return emps;
}
}
와 POJO로 XML을 구문 분석하는 코드입니다 :
:package testPkg4;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import request.Bean;
import request.Employee;
import request.Employees;
public class Test4 {
public static void main(String[] args) {
XmlMapper xmlMapper = new XmlMapper();
//Bean value = new Bean();
Employees emps=new Employees();
try {
emps = xmlMapper.readValue(new File("D:\\workspace\\test\\src\\test\\resources\\employee.xml"),
Employees.class);
} catch (IOException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
System.out.println(emps.getEmployees().get(0).getFirstName());
//System.out.println(e.getFirstName());
//System.out.println(emps.getEmployees().get(0).getThirdElement());
}
}
지금 여기에 내가 점점 오전 오류입니다
com.fasterxml.jackson.databind.JsonMappingException : 해당 사항 없음 [출처 : D : \ workspace \ test \ src \ test \ resources \ employee.xml;com.fasterxml.jackson.databind.JsonMappingException.from (JsonMappingException.java:277) com.fasterxml에서 에있는 참조 행을 통해 (참조 체인을 통해) : 12] (참조 체인을 통해 request.Employees [ "employee"]). jackson.databind.deser.SettableBeanProperty._throwAsIOE com.fasterxml.jackson.databind.deser.SettableBeanProperty._throwAsIOE (SettableBeanProperty.java:532)에서 (SettableBeanProperty.java:551) com.fasterxml.jackson.databind에서 . com.fasterxml.jackson.dat에서 deser.impl.MethodProperty.deserializeAndSet com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize (BeanDeserializer.java:276)에서 (MethodProperty.java:108) com.fasterxml.jackson.databind.ObjectMapper.readValue에서 abind.deser.BeanDeserializer.deserialize com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose (ObjectMapper.java:3814)에서 (BeanDeserializer.java:140) ( sun.reflect.NativeMethodAccessorImpl에서 request.Employees.setEmployees (Employees.java:31)에서 java.lang.NullPointerException이 : testPkg4.Test4.main (Test4.java:23)에서 ObjectMapper.java:2756) 에 의한에서 java.lang.reflect.Method.invoke (알 수없는 소스)에서 sun.reflect.DelegatingMethodAccessorImpl.invoke (알 수없는 소스)에서 sun.reflect.NativeMethodAccessorImpl.invoke (알 수없는 소스)에서 .invoke0 (기본 방법)3210 com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet (MethodProperty.java:106) ... 5 "main"스레드의 예외 java.lang.NullPointerException at testPkg4.Test4.main (Test4. 자바 : 29)
내가 thsi XML 파일을 구문 분석하고있는 동안 :
<employees>
<employee>
<name>ASHISH</name>
<roles>MD</roles>
</employee>
<employee>
<name>BAHADUR</name>
<roles>CO</roles>
<roles>TM</roles>
</employee>
</employees>
사람이 나에게 문제의 의미를 알아내는 데 도움이 있습니다!