Read Location from DataContainer


Hi!, im trying to read JSON that i stored using

DataContainer container = DataContainer.createNew()
.set(DataQuery.of(“Location”), location)
.set(DataQuery.of(“count”), dataCount);

DataFormats.JSON.writeTo(fileStream, container);

But when i try to read that i can only read the count but Location no return an Object with

Optional optLocation = container.getObject(DataQuery.of(“Location”), Location.class);

But in the json file the data exists without problem.


Anyone know how can i read that Location?


There are four kinds of things which you can use on a DataContainer:

  • natively supported things, which have dedicated methods like getString/List
  • catalog types, which are used with getCatalogType/List
  • types with a registered DataTranslator, which are used with getObject/List
  • types that implement DataSerializable, which are used with getSerializable/List

Location<World> is a DataSerializable, which means you should be using getSerializable. But you are using getObject instead, which is why it is failing.