user3369592 user3369592 - 1 year ago 88
Java Question

Can not deserialize instance of parseJason when using Jackson to parse the Json File

I have a Json file :

"name":"First Red Flash",
"pull down bottle",
"unscrew lid",
"dump pills out",
"screw lid on",
"put bottle away"


I tried to parse this Json file using the Jackson.
I wrote the following code:

public class Holder{
public Holder(){};
//getter and setters

String name;
List<String> subEventTypes = new ArrayList<>();
Double time;
String $$hashKey;
Double endTime;
List<Double> subEventSplits = new ArrayList<>();

class MapperClass{
List<Holder> list = new ArrayList<>();

public static void main(String[] args) throws JsonProcessingException, IOException
ObjectMapper mapper = new ObjectMapper();
List<Holder> list = mapper.readValue(new File("data.json"), mapper.getTypeFactory().constructCollectionType(
List.class, Holder.class));


When I run the program, it showed this error : "

No suitable constructor found for type [simple type, class parseJason$Holder]: can not instantiate from JSON object (need to add/enable type information?)

Is there anything wrong with my code? or I have to use another way to parse my Json file.

Answer Source


list = mapper.readValue(
                        List.class, Holder.class));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download