![](/img/trans.png)
[英]How to convert list of json objects to pojo list of strings that contains some field from each object?
[英]How to retrieve Arraylist/list from json rest request and convert into pojo object (one of pojo variable is of list type.)
如何从JSON REST请求中检索ArrayList
/ List
并转换为POJO对象(POJO变量之一是列表类型)。
//域类
@Service
@JsonIgnoreProperties(ignoreUnknown = true)
public class DocumentProps {
@JsonProperty("name")
private String name;
@JsonProperty("type")
private String type;
@JsonProperty("properties") // list variable
private List properties;
//控制器类
@RestController
public class springteamplate {
@Autowired
DocumentProps docprops;
@GetMapping(value = "/get")
private void getEmployees()
{
final String uri = "http://xyz";
docprops = RestTemplateBuild.template.getForObject(uri, DocumentProps.class);
System.out.println(docprops.getName()); // able to retrieve name
System.out.println(docprops.getType()); // able to retrieve type
System.out.println(docprops.getPrpopertie()); // How to retrieve list of properties.
}}
您可以使用ParameterizedTypeReference
获取集合类型或泛型类型绑定。
The purpose of this class is to enable capturing and passing a generic Type.In order to capture the generic type and retain it at runtime, you need to create a subclass (ideally as anonymous inline class) as follows:
ParameterizedTypeReference<List<String>> typeRef = new ParameterizedTypeReference<List<String>>() {};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.