Read Location from DataContainer


#1

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.

“Location”:{“ContentVersion”:1,“WorldName”:“world”,“WorldUuid”:“7659ae1a-22a9-4a32-bf8a-298a43b410e2”,“BlockType”:“minecraft:chest”,“X”:-46.05715257516578,“Y”:74.0,“Z”:221.91953494386158}

Anyone know how can i read that Location?


#2

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.