Java開発でObjectMapperを使ってreadValue()のサンプルコード
Javaコード:
public class JsonToJavaBean {
public static void main(String[] args) {
String str="{\"employee\":[{\"name\":\"yamadag\",\"age\":27},
{\"name\":\"saori\",\"age\":28}
]
}";
Employee emp = null;
List<Employee> list = null;
try {
ObjectMapper objectMapper=new ObjectMapper();
EmployeeList empList=objectMapper.readValue(str, EmployeeList.class);
list=employeeList.getEmployee();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for(Employee vm:list){
System.out.println(vm.getName()+" “+vm.getAge());
}
}
}