且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从START_ARRAY标记中反序列化java.util.HashMap的实例

更新时间: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.