Spring - Java将HashMap映射到多层Pojo

时间:2017-06-23 02:04:36

标签: java spring hashmap pojo

我的哈希映射Map<String, String>具有以下值,请注意点表示层次结构:

+--------------------+-----------+
|    Key             |  Value    |
+--------------------+-----------+
| car.color          | blue      |
| car.engine.make    | mitsubishi|
| car.engine.power   | 120       |
+--------------------+-----------+

我有pojo课程:

public class Vehicle {

    private Car car;
   **Setters and Getters Below*  
}    

public class Car {
    private String color;

    private Engine engine;
    **Setters and Getters Below*      
}

public class Engine {
    private String make;

    private Integer power;
    **Setters and Getters Below**
}

有什么方法可以根据层次结构将HashMap映射到POJO类?我试图使用jackson ObjectMapper mapper = new ObjectMapper();但它似乎能够映射1级对象。

0 个答案:

没有答案