Searching for a up-to-date item serializer

Discussion in 'Spigot Plugin Development' started by Shadow48402, May 12, 2016.

  1. Hi guys,

    It has been a long time since I've posted something here, good to be back. I have a question today, do one of you guys have a premade class for serializing that's up-to-date, I've been trying different classes that can be found online but they are not complete (missing lores, enchantements etc.). The class will be used for MySQL data storing.

    Thank you.

    Shadow
     
  2. Bukkit has it's own item Serialiser (the ItemStacks extend Serialisable). I unfortunately dont know how to use it but I don't believe it is too complicated (maybe even as simple as saving an itemstack to a config/file)
     
  3. MiniDigger

    Supporter

  4. I am aware of that fact, tried it too, but I need to store it as a string not a map, and yes I know that you can .toString() the map but how do you go back from the a string to the map? ^^
     
  5. MiniDigger

    Supporter

    do you need to have it readable? if not, you can use a bukkitobjectoutput stream to write it to a string and load that string via a bukkitobjectinut stream
     
  6. I am using the .serialize function now, and setting it toString(), but how can I restore the map from that string?
    Code (Text):

    String item = p.getItemInHand().serialize().toString();
     
     
  7. Write your own serialization method?
     
  8. That would be an option, but the stored item has to be readable through a web interface too.

    Beside of that:
    Code (Text):

    Caused by: java.lang.ClassCastException: org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack cannot be cast to java.io.Serializable
     
     
    #9 Shadow48402, May 12, 2016
    Last edited: May 12, 2016
  9. If you're saving to yaml, FileConfiguration#set( String, ItemStack ); and (ItemStack)FileConfiguration#get( String ); will suffice, otherwise serializing and deserializing a map to a string is pretty easy.. You could use GSON? Depending on your preferences.
     
    • Agree Agree x 1
  10. No I am not saving it into a YAML file, like said before, I have found some ways to serialize/deserialize it into/from the MySQL database. But my problem is that I need the information for a web interface too, so I am thinking about writing an own function to store it in a JSON format.
     
    • Funny Funny x 1
  11. MiniDigger

    Supporter

    as Cory suggested: use the ConfigurationSeriable for itemstack <-> map<String,object> and convert that map into a string using json/gson. thats the easiest way to serialize a itemstack into a string
     
  12. I want a signature like that! Woah!
     
    • Friendly Friendly x 1
  13. MiniDigger

    Supporter

    you must be new that you never saw his signiture ^^
     
  14. First time I felt like commenting on it.

    Member Since:
    Dec 21, 2015
     
  15. MiniDigger

    Supporter

    I know, I checked that before writing this comment ;)
    If you look at his profile you can see that everyone likes his signiture ^^
     
    • Agree Agree x 1
  16. its sexy.
     
  17. YAML can be a string stored in a database under the TEXT type...

    Whatever you use, you're going to have to deserialize them on the web end via some sort of processing.. Be it client side or server side.. That's all your doing, I'd be using JSON since it's compatible with js(obviously), and PHP which I presume you're using.