Solved GSON formats ugly when writing to document/file

Discussion in 'Plugin Development' started by DoggyCode™, Nov 23, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    DoggyCode™

    hey, I've got a nice JSON file looking like this:
    PHP:
    {
      
    "working":"yup",
      
    "players": [
        {
          
    "uuid":"uuid1",
          
    "lives":0
        
    },
        {
          
    "uuid":"uuid2",
          
    "lives":0
        
    }
      ]
    }
    However, when I convert this to a Java object to use, then this object back to JSON using
    PHP:
    JavaObject o the object;
    Gson gson = new Gson();
    try (
    FileWriter writer = new FileWriter(new File(thefile))) {
      
    gson.toJson(owriter);
    } catch (
    IOException e) {
      
    e.printStackTrace();
    }
    Everything changes from a neat JSON setup (as seen above), to:
    PHP:
    {"working":"yup","players": [{"uuid":"uuid1","lives":0},{"uuid":"uuid2","lives":0}]}
    Now this isn't that bad, because you are not really supposed to go in and edit stuff in that file (that's only for the plugin to do), but I think it would be nice if you would be able to take a sneak peak at the data without having to ball your eyes out.

    Any help is appreciated!
     
  2. Online

    timtower Administrator Administrator Moderator

  3. Offline

    DoggyCode™

Thread Status:
Not open for further replies.

Share This Page