更新时间:2022-06-05 17:08:59
创建一个简单的 pojo
Class First
Create a simple pojo
Class First
class MyClass
{
@JsonProperty
private String Name;
@JsonProperty
private String CreationDate;
}
并使用此代码......
and use this code...
byte[] mapData = Files.readAllBytes(Paths.get("process.txt"));
ObjectMapper objectMapper=new ObjectMapper();
//add this line
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<MyClass> myObjects = mapper.readValue(mapData , new TypeReference<List<MyClass>>(){});
或
byte[] mapData = Files.readAllBytes(Paths.get("process.txt"));
ObjectMapper objectMapper=new ObjectMapper();
//add this line
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
List<MyClass> myObjects = mapper.readValue(mapData , mapper.getTypeFactory().constructCollectionType(List.class, MyClass.class));
myObjects
将包含
。现在,您可以根据自己的要求访问此列表。列表
MyClass
myObjects
will contains the List
of MyClass
. Now you can access this list as per your requirement.