Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jackson中的@XmlPath模拟是什么?_Java_Xml_Xpath_Jackson_Moxy - Fatal编程技术网

Java jackson中的@XmlPath模拟是什么?

Java jackson中的@XmlPath模拟是什么?,java,xml,xpath,jackson,moxy,Java,Xml,Xpath,Jackson,Moxy,使用org.eclipse.persistence.oxm.annotations.XmlPath可以将相同的元素放入单独的类字段中。杰克逊有模拟注释吗?模拟是 给出关于XmlPath问题中的示例,我创建了以下示例: 输入Json { "response": { "employee": [ {"name":"Sharique"}, {"name":24}, {"name":"India"} ]} } 目标POJO: public class Employ

使用
org.eclipse.persistence.oxm.annotations.XmlPath
可以将相同的元素放入单独的类字段中。杰克逊有模拟注释吗?

模拟是

给出关于XmlPath问题中的示例,我创建了以下示例:

输入Json

{ "response": 
  { "employee": [ 
    {"name":"Sharique"}, 
    {"name":24}, 
    {"name":"India"}
  ]}
}
目标POJO:

public class Employee
{
    @JsonPath("$.response.employee[0].name")
    private String empName;
    @JsonPath("$.response.employee[1].name")
    private int age;
    @JsonPath("$.response.employee[2].name")
    private String country;

    public String getEmpName() { return empName; }
    public void   setEmpName(String empName) { this.empName = empName; }
    public int    getAge() { return age; }
    public void   setAge(int age) { this.age = age; }
    public String getCountry() { return country; }
    public void   setCountry(String country) { this.country = country; }
}
调用:

public static void main(String[] args)
{
    String json = "{ \"response\": { \"employee\": [ {\"name\":\"Sharique\"}, {\"name\":24}, {\"name\":\"India\"}] }}";

    try {
        JsonUnmarshaller unmarshaller = new DefaultJsonUnmarshaller();
        Employee emp = unmarshaller.unmarshal(Employee.class, json);
        System.out.println(emp.getEmpName() + " " + emp.getAge() + " " + emp.getCountry());
    } catch (Exception e) {
        e.printStackTrace();
    }
输出:

Sharique 24 India