Serializable objects with configure

I am so lost atm … . I am trying to store a claim class in a config file.

package com.thomas15v.landguard.protection;

import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;

import java.io.Serializable;
import java.util.UUID;
//attempt3
@ConfigSerializable
                            //attemp1 \/
public class Claim implements Serializable  {

     //attemp2
    @Setting
    private UUID player;
    @Setting
    private ClaimLocation location;

    public Claim(UUID player, ClaimLocation location){
        this.player = player;
        this.location = location;
    }

    public ClaimLocation getLocation() {
        return location;
    }

    public UUID getPlayer() {
        return player;
    }
}

But it keeps throwing this:

    Caused by: com.typesafe.config.ConfigException$BugOrBroken: bug in method caller: not valid to create ConfigValue from: com.thomas15v.landguard.protection.Claim@5f59c9b
	at com.typesafe.config.impl.ConfigImpl.fromAnyRef(ConfigImpl.java:275) ~[ConfigImpl.class:?]
	at com.typesafe.config.impl.ConfigImpl.fromAnyRef(ConfigImpl.java:253) ~[ConfigImpl.class:?]
	at com.typesafe.config.impl.ConfigImpl.fromAnyRef(ConfigImpl.java:193) ~[ConfigImpl.class:?]
	at com.typesafe.config.ConfigValueFactory.fromAnyRef(ConfigValueFactory.java:66) ~[ConfigValueFactory.class:?]
	at ninja.leaping.configurate.hocon.HoconConfigurationLoader.saveInternal(HoconConfigurationLoader.java:167) ~[HoconConfigurationLoader.class:?]
	at ninja.leaping.configurate.loader.AbstractConfigurationLoader.save(AbstractConfigurationLoader.java:144) ~[AbstractConfigurationLoader.class:?]
	at com.thomas15v.landguard.config.GenericConfig.save(GenericConfig.java:32) ~[GenericConfig.class:?]
	at com.thomas15v.landguard.config.ClaimsConfig.addClaim(ClaimsConfig.java:18) ~[ClaimsConfig.class:?]
	at com.thomas15v.landguard.LandGuardPlugin.onEnabled(LandGuardPlugin.java:48) ~[LandGuardPlugin.class:?]
	... 30 more

Adding method:

public void addClaim(Claim claim){
        //getRoot() returns a ConfigurationNode, see https://gist.github.com/thomas15v/645bbf6827ff2d4953b3
        getRoot().getNode(claim.getLocation().toString()).setValue(claim);
        try {
            save();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

you have to serialize using the ObjectMapper -> http://zml2008.github.io/configurate/apidocs/ninja/leaping/configurate/objectmapping/ObjectMapper.html
to serialize the object to a given node

2 Likes

Oh I see. The only problem is that their is no serializer for UUID :worried:. I could solve that if I store the UUID as a string but yeah … .
http://hastebin.com/exisawidev.avrasm

UUID.toString();
and
UUID.fromString(String);

Yeah I know about that. But that’s messy ya know.
I think I am just going to do this aproach :cat:. Relay/GatewayStorageService.java at master · mmonkey/Relay · GitHub

I’ve added a UUID type serializer in configurate 1.2 and bumped that release. I’ll update Sponge to use it once it syncs to mvn central, but soon you should be able to directly use UUIDs (prolly by tomorrow).

3 Likes