My question is once I serialize an object and then if I change the object it won't be able to deserialize anymore, does anyone know a good work around?
xCyanide If the object implements java.io.Serializable, use an ObjectInputStream to read it. If it is a ConfigurationSerializable, use MemorySection#get(String) and cast to your object.
xTrollxDudex Yeah I know that, my object implements java.io.Serializable and when I convert it to a string and then change the object it can't deserialize. Is there a way to fix that, because I might be changing the object pretty often.
xCyanide Again, open an ObjectInputStream and use readObject to get your Object, and cast to it. Make sure to close so you don't get memory leaks.
xTrollxDudex I did that and it works fine if I don't change anything, but once I edit the class(like add a method or something) I get this error Code: java.io.InvalidClassException: me.xCyanide.xguilds.objects.Guild; local class incompatible: stream classdesc serialVersionUID = 6353559673903595198, local class serialVersionUID = 7338525152735826050 [21:55:56] [Server thread/WARN]: at java.io.ObjectStreamClass.initNonProxy(Unknown Source) [21:55:56] [Server thread/WARN]: at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source) [21:55:56] [Server thread/WARN]: at java.io.ObjectInputStream.readClassDesc(Unknown Source) [21:55:56] [Server thread/WARN]: at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source) [21:55:56] [Server thread/WARN]: at java.io.ObjectInputStream.readObject0(Unknown Source) [21:55:56] [Server thread/WARN]: at java.io.ObjectInputStream.readObject(Unknown Source) [21:55:56] [Server thread/WARN]: at me.xCyanide.xguilds.managers.DataManager.fromString(DataManager.java:43) [21:55:56] [Server thread/WARN]: at me.xCyanide.xguilds.managers.DataManager.loadGuilds(DataManager.java:87) [21:55:56] [Server thread/WARN]: at me.xCyanide.xguilds.managers.GuildManager.loadGuilds(GuildManager.java:24) [21:55:56] [Server thread/WARN]: at me.xCyanide.xguilds.xGuilds.onEnable(xGuilds.java:46) [21:55:56] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:218) [21:55:56] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457) [21:55:56] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:385) [21:55:56] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugin(CraftServer.java:302) [21:55:56] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_7_R1.CraftServer.enablePlugins(CraftServer.java:284) [21:55:56] [Server thread/WARN]: at net.minecraft.server.v1_7_R1.MinecraftServer.m(MinecraftServer.java:348) [21:55:56] [Server thread/WARN]: at net.minecraft.server.v1_7_R1.MinecraftServer.g(MinecraftServer.java:325) [21:55:56] [Server thread/WARN]: at net.minecraft.server.v1_7_R1.MinecraftServer.a(MinecraftServer.java:281) [21:55:56] [Server thread/WARN]: at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:186) [21:55:56] [Server thread/WARN]: at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:430) [21:55:56] [Server thread/WARN]: at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617)
xTrollxDudex I actually don't know how to do that because I only serialize when the player changes a string via command and I deserialize the object in the onEnable method. So if I change the class, the data won't be able to load. Sorry if I am not explaining this correctly.
I just added a serialVersionUID to the class that implements serializable and whenever I load the object I just reserialized it. This ended up working for me.