Java 使用JSON数据创建POJO

Java 使用JSON数据创建POJO,java,json,rest,jaxb,Java,Json,Rest,Jaxb,我有一个JSON来自RESTAPI的响应负载。下面是简化JSON的结构,但实际的结构要复杂得多 { "hardware": { "cores": 2, "cpu": 1, }, "name": "machine11", "network": [ { "interface_name": "intf1", "interface_ip": "1.1.1.1",

我有一个JSON来自RESTAPI的响应负载。下面是简化JSON的结构,但实际的结构要复杂得多

{
    "hardware": {
        "cores": 2,
        "cpu": 1,
    },
    "name": "machine11",
    "network": [
        {
            "interface_name": "intf1",
            "interface_ip": "1.1.1.1",
            "interface_mac": "aa : aa: aa: aa: aa"
        }
     ]
}
现在我必须编写POJO类来使用JAXB注释(javax.xml.bind.annotation.*)绑定JSON结构。 有谁能帮助我如何为复杂的JSON结构编写POJO类,将JSON转换为XML,然后使用XML模式生成类是没有帮助的,还有其他方法吗?
提前感谢:-)

根据上述JSON结构,您的Java对象将如下所示:

public class OutermostClass{

    private Hardware hardware;
    private String name;
    private Set<Network> network = new HashSet<Network>;

}

public class Hardware {

    private int cores;
    private int cpu;
}

public class Network {
    private String interface_name;
    private String interface_ip;
    private String interface_mac
}
公共类最外层类{
专用硬件;
私有字符串名称;
专用集网络=新哈希集;
}
公共级硬件{
私有int核;
专用int cpu;
}
公共班级网络{
私有字符串接口名称;
私有字符串接口;
专用字符串接口
}

检查。该站点帮助将JSON转换为POJO类。还有JSON32POJO maven插件。参考链接:文件中不允许有多个公共