Custom TypeSerializer not working

Hey guys, I’m trying to easily Serialize a location to the config file.

My class:
public class LocationSerializer implements TypeSerializer<Location>
{
@Override
public Location deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException
{
String name = value.getNode(“world”).getValue(TypeToken.of(String.class));
double X = value.getNode(“X”).getValue(TypeToken.of(double.class));
double Y = value.getNode(“Y”).getValue(TypeToken.of(double.class));
double Z = value.getNode(“Z”).getValue(TypeToken.of(double.class));

    if (!Sponge.getServer().getWorld(name).isPresent())
    {
        System.out.println("The world doesn't exist");
        return null;
    }

    return Sponge.getServer().getWorld(name).get().getLocation(X, Y, Z);
}

@Override
public void serialize(TypeToken<?> type, Location<World> loc, ConfigurationNode value) throws ObjectMappingException
{
    value.getNode("world").setValue(Sponge.getServer().getWorld(loc.createSnapshot().getWorldUniqueId()).get().getName());
    value.getNode("X").setValue(loc.getX());
    value.getNode("Y").setValue(loc.getY());
    value.getNode("Z").setValue(loc.getZ());
}

}

@Listener public void onServerStart(GameStartedServerEvent event)
{
ConfigurationOptions.defaults().getSerializers().newChild().register(TypeToken.of(Location.class), new LocationSerializer());
}

But I keep getting this stupid error: Error:(66,68) java: no suitable method found for register(com.google.common.reflect.TypeToken<org.spongepowered.api.world.Location>,LocationSerializer) <- this is an error related to the line on onServerStart but my Intellij says there’s no error…

What version of Sponge API is on your server and Intelij?

The thing is the jar is never built because of this error so it’s not on the server. But for both of them I’m using the 7.2.0 and I tried following the examples in the wiki but these methods are now deprecated and also give me an arrow.

I have just compiled using API 7.3 the following code, however I get the error that the register method and withSuggestions with 7.2.0 stating that they do not exsit.

        TypeSerializerCollection serializer = ConfigurationOptions.defaults().getSerializers().newChild();
        serializer.register(TypeToken.of(String.class), null);
        ConfigurationOptions.defaults().withSerializers(serializer);

Its clear that your Intelij has Sponge API 7.3, however gradle builds against 7.2. set it to 7.3 and it should be fine

as for being deprecated, im assuming you mean setSerializers. In Sponge if something is deprecated they will state why and typically offer a alternative within the Javadocs, which you can read on github as well as the javadocs.

Thanks for your help but it isn’t working. I’m using maven to build the jar and I switched to api version 7.3 in my pom.

My current code:
TypeSerializerCollection serializer = ConfigurationOptions.defaults().getSerializers().newChild();
serializer.register(TypeToken.of(Location.class), new LocationSerializer());
ConfigurationOptions.defaults().withSerializers(serializer);

The error when try to do maven install:
Error:(65,19) java: no suitable method found for register(com.google.common.reflect.TypeToken<org.spongepowered.api.world.Location>,fr.mysteriouscraft.plugin.LocationSerializer)

If you clear out your maven cache, just to make sure that its not attempting to use the old version of configurate. To clear it out on Windows, delete the following folder

C:/Users/<your user profile>/.m2 

(You may need to show hidden folders) on other OS, just go to your user profile and find the .m2 folder.

After that right click the Intelij module and click maven -> refresh depends

Still the same error even though I did what you said

I got it to work thanks to someone on the discord

What was the issue?

TypeSerializerCollection.create().newChild().register(new TypeToken<Location>() {}, new LocationSerializer());