0

I'm trying to load a value taken from a JSON file. The target object where -reloading the JSON file is:

HashMap<String,LinkedList<Investor>> investors_per_location=new HashMap<>();

What I'm doing is creating a couple of Types:

                MapType mapType = null;
                CollectionType mapTypeAux = null;
                mapTypeAux = typeFactory.constructCollectionType(LinkedList.class,Investor.class);                  
                mapType = typeFactory.constructMapType(HashMap.class, String.class,mapTypeAux.getClass());
                investors_per_location=objectMapper.readValue(jsonData, mapType);

My best guess is that, this is not the way to include a linkedlist within a hashmap to load it back from a JSON file. Any clue? Thx in advance, David.

David G. Hdez
  • 125
  • 1
  • 8

1 Answers1

0

Try using TypeReference instead:

TypeReference<Map<String, LinkedList<Investor>>> typeRef = new TypeReference<Map<String, LinkedList<Investor>>>(){};
Map<String, LinkedList<Investor>> investorsPerLocation = objectMapper.readValue(jsonData, typeRef);
Mafor
  • 9,668
  • 2
  • 21
  • 36