Save/load items to database

Discussion in 'Spigot Plugin Development' started by Sognus, May 5, 2015.

  1. I recently started working on way that allows me to save information about an item to database including actual metadata.

    When I'm saving items to database I just take item, get basic information from it (id, durability, etc.). I have no problem when i got ItemMeta, serialize it to HashMap and then used Gson to transfer it to string json, which i can save to database finally.

    Real problem occurs when I am trying to load that item from database. I thought it would be enough when I reverse way I am saving items. I thought i would be just get the metadata string (json) from database, transfer it to HashMap and then somehow deserialize it to itemMeta object, with which I could just set ItemMeta for item, which I am loading.


    I finally got to my question: Is there any way to save item with metadata in human readable form to database or is there any way to fix my code? My goal is save every single item in game to database and sucessfully load it from database to game. Is this even possible?

    Note: Please don't blame me if I have code that is absolutely wrong or inefficient. I am beginner in java and bukkit/spigot development. Sorry for mistakes i have made in this text.
     
  2. Im curious as to why you would want to do this? You could save it to make it more human readable but the way you have it I think it looks okay, your just creating more work for yourself making it look pretty to the eye.
     
  3. I have to do it human readable in database because this plugin will consist two parts: server part (this) and web part, where we have to decode saved item and display it on website including enchants, custom item name/lore/other metadata. If it would be better readable than raw bytes encoded to base64, it makes item display on web much easier.
     
  4. I solve that by using different serialization/deserialization method, if someone want to know, how i made it, feel free to read a code.

    You may lock this thread.