[LIB][WIP] JsonConfiguration - JSON implementation of FileConfiguration.

Discussion in 'Resources' started by dumptruckman, Jan 30, 2013.

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

    dumptruckman

    Tired of YAML for your configuration files? You probably shouldn't be. This library provides a simple class (JsonConfiguration) for creating configurations that are storable in JSON format. It can store all the data currently capable of being stored by YamlConfiguration. Yes, that means ItemMeta.

    Pros:
    • Less white-space!
      • This was my primary reason for designing this. With the advent of ItemMeta, storing an ItemStack in Yaml has the potential to produce a lot of extra white-space in the file. (tabs/new-lines).
      • JsonConfiguration produces a single line of text in a file.
    • Probably faster!
    Cons:
    • Less user-friendly
      • Since everything is stored on one line in the file, it makes sorting it out manually much more difficult. This means this JsonConfiguration is really intended for data files only.
    • No room for comments
      • JSON does not have a concept of comments like YAML does.
    • Not as flexible as YAML
      • As the saying goes, all JSON is YAML but not all YAML is JSON. YAML is capable of a few things JSON is not. However, I do not believe these things are supported by YamlConfiguration.
    Jenkins: http://ci.onarandombox.com/job/JsonConfiguration/
    Javadoc: http://ci.onarandombox.com/job/JsonConfiguration/javadoc/
    Source: https://github.com/dumptruckman/JsonConfiguration/

    Currently only available via maven.

    Repository: http://repo.onarandombox.com/content/groups/public/
    HTML:
    <!--...-->
    <repository>
        <id>onarandombox</id>
        <url>http://repo.onarandombox.com/content/groups/public/</url>
    </repository>
    <!--...-->
    <dependency>
        <groupId>com.dumptruckman.minecraft</groupId>
        <artifactId>JsonConfiguration</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <!--...-->
    
    This lib also requires the json-smart lib to be present. I have not shaded it in already. It is available on the central maven repository. Unfortunately json-simple was not an option due to its inability to properly deal with integers.

    HTML:
    <!--...-->
    <dependency>
        <groupId>net.minidev</groupId>
        <artifactId>json-smart</artifactId>
        <version>1.1.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <!--...-->
    
     
  2. Offline

    p000ison

  3. Offline

    turt2live

    Dependency information is wrong, should be:



    dumptruckman fixed it
     
  4. Offline

    SnoFox

    ...
    .prettyPrint(); ?

    Does json-smart not have a pretty print method/settings? I used Jackson FasterXML (badly named library; it does Json) to write out some Json for a different project, and it will happily print out human-readable Json.

    Code:java
    1. @SuppressWarnings("unchecked")
    2. public static void doJsonThings() {
    3. File json = new File(dir, "file.json");
    4. ObjectMapper mapper = new ObjectMapper();
    5. mapper.configure(SerializationFeature.INDENT_OUTPUT, true); // This is the important thing in Jackson FasterXML for pretty printing
    6. // Do cool things with your json file
    7. try {
    8. mapper.writeValue(json, jsonRoot);
    9. } catch (IOException e) {
    10. e.printStackTrace();
    11. showFailureDialog("Unable to write profiles JSON file.");
    12. }
    13. }
     
  5. Offline

    dumptruckman

    I could probably add that.
     
  6. Offline

    drtshock

    lol. but nice ;3

    Did you try using the gson version that is in craftbukkit? ;o
     
  7. Offline

    SnoFox

Thread Status:
Not open for further replies.

Share This Page