![](/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.