There is a library for storing key-value , Hawk .

If I have for example: List<Animal> animals , which is filled with elements:

 animals.add(new Horse()); animals.add(new Cat()); animals.add(new Dog()); 

I save it in Hawk , and when I take it back, all the animals are saved of the desired type, but if I have a Box object containing a List<Animal> animals and I save it, then I will have a list from Animal that I cannot convert in Horse , etc ..

  • one
    Show more code. So far the problem is not clear, but it is most likely in the Box class - Yuriy SPb
  • The Box class is just a container. There's only a field List <Animal> - Chickin Nick
  • one
    Save in the list a tuple in which the source object and its class will be. According to this record, it will be possible to cast to the original type - Artem Konovalov
  • And if you check for instanceof in a loop, each of the List <Animals>? For each of the three classes (Horse, Cat, Dog)? - Chubatiy
  • The instanceof is quite long and is worth using it only for debugging purposes. - DimXenon

1 answer 1

In the end, I abandoned Hawk, tried another tool, Paper, where it all worked. Still, it's better to write some things with your hands.