{"id":28476536,"url":"https://github.com/grabsky/configuration","last_synced_at":"2026-03-05T22:13:52.231Z","repository":{"id":60864326,"uuid":"539997347","full_name":"Grabsky/configuration","owner":"Grabsky","description":"Small configuration library based on square/moshi which aims to provide an easy way to map JSON files to static fields.","archived":false,"fork":false,"pushed_at":"2025-03-24T17:22:01.000Z","size":319,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-07T15:07:12.706Z","etag":null,"topics":["gson","java","json","paper"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Grabsky.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-22T13:32:21.000Z","updated_at":"2025-03-24T17:22:04.000Z","dependencies_parsed_at":"2024-07-14T22:40:40.302Z","dependency_job_id":"ffe10ea9-1208-4f89-8c77-ff6d6a2e65f4","html_url":"https://github.com/Grabsky/configuration","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Grabsky/configuration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grabsky%2Fconfiguration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grabsky%2Fconfiguration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grabsky%2Fconfiguration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grabsky%2Fconfiguration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Grabsky","download_url":"https://codeload.github.com/Grabsky/configuration/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Grabsky%2Fconfiguration/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263175468,"owners_count":23425576,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gson","java","json","paper"],"created_at":"2025-06-07T15:07:12.022Z","updated_at":"2026-03-03T13:02:48.173Z","avatar_url":"https://github.com/Grabsky.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# configuration\n\u003cspan\u003e\n    \u003ca href=\"\"\u003e\u003cimg alt=\"Build Status\" src=\"https://img.shields.io/github/actions/workflow/status/Grabsky/configuration/gradle.yml?style=for-the-badge\u0026logo=github\u0026logoColor=white\u0026label=%20\"\u003e\u003c/a\u003e\n    \u003ca href=\"\"\u003e\u003cimg alt=\"CodeFactor Grade\" src=\"https://img.shields.io/codefactor/grade/github/Grabsky/configuration/main?style=for-the-badge\u0026logo=codefactor\u0026logoColor=white\u0026label=%20\"\u003e\u003c/a\u003e\n\u003c/span\u003e\n\u003cp\u003e\u003c/p\u003e\n\nSmall configuration library based on **[square/moshi](https://github.com/square/moshi)** which aims to provide an easy way to map JSON files to static fields.\n\n\u003cbr /\u003e\n\n## Requirements\n### [Core](#usage)\nRequires **Java 21** (or higher).  \n\n### [Paper Module](https://github.com/Grabsky/configuration/blob/main/PAPER_MODULE.md)\nRequires **Java 21** (or higher) and **Paper 1.21.3** (or higher).\n\n\u003cbr /\u003e\n\n## Getting Started\nLibrary is published to the **[GitHub Packages Registry](https://github.com/Grabsky/configuration/packages/)** and may require additional configuration. You can find more details **[here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-gradle-registry#using-a-published-package)**.\n```groovy\nrepositories {\n    maven { url = \"https://maven.pkg.github.com/grabsky/configuration\"\n        credentials {\n            username = findProperty(\"gpr.actor\") ?: System.getenv(\"GITHUB_ACTOR\")\n            password = findProperty(\"gpr.token\") ?: System.getenv(\"GITHUB_TOKEN\")\n        }\n    }\n}\n```\n\n```groovy\ndependencies {\n    // CORE\n    implementation 'cloud.grabsky:configuration:[_VERSION_]'\n    // OPTIONAL PAPER MODULE\n    implementation 'cloud.grabsky:configuration-paper:[_VERSION_]'\n}\n```\n\n\u003cbr /\u003e\n\n## Usage\n\nThis is contents of example JSON file located at `classpath/resources/settings.json`:\n```json5\n{\n    \"settings\": {\n        \"debug\": false,\n        \"nullable\": null,\n        \"positive_integer\": 35,\n        \"static_final\": \"Ignored.\"\n    }\n}\n```\n\nThis is how our `ApplicationSettings` can look like, please read comments:\n```java\npublic final class ApplicationSettings extends Configuration {\n\n    // @JsonPath specifies a path to the value.\n    @JsonPath(\"settings.debug\")\n    public static Boolean DEBUG;\n    \n    // @JsonNullable indicates that JsonAdapter#fromJson returning null is 100% valid and no exception should be thrown.\n    @JsonNullable\n    @JsonPath(\"settings.nullable\")\n    public static String NULLABLE;\n    \n    // @JsonAdapter allows you to specify on-demand JsonAdapter that is going to be used for that field.\n    @JsonPath(\"settings.positive_integer\")\n    @JsonAdapter(fromJson = PositiveIntegerAdapter.class)\n    public static Integer POSITIVE_INTEGER;\n    \n    // This field is ignored because it is not annotated with @JsonPath.\n    public static Boolean NOT_ANNOTATED;\n    \n    // This field is ignored because:\n    //   1. It's not static.\n    //   2. It's final.\n    // Only public, static, non-final fields can be used for mapping.\n    @JsonPath(\"settings.static_final\")\n    public final Boolean STATIC_FINAL = true;\n    \n    // Override this method to run some code after re-mapping have finished.\n    @Override\n    public void onReload() {\n        System.out.println(\"Reload succeeded with no errors.\");\n    }\n    \n}\n```\n\nMapping example, please read comments:\n```java\npublic class MainApplication extends Application {\n    \n    private Moshi moshi;\n    private ConfigurationMapper mapper;\n\n    @Override\n    public void initialize() {\n        // Creating an instance of Moshi.\n        this.moshi = new Moshi.Builder().build();\n\n        // Creating an instance of ConfigurationMapper.\n        this.mapper = ConfigurationMapper.create(moshi);\n        \n        try {\n            // Running some logic to copy file from 'resources' to desired directory.\n            final File file = ensureResourceExistence(\"settings.json\", new File(\"./config/settings.json\"));\n            // Mapping file contents. Below method is going to fail when:\n            //   1. An exception is thrown during the JSON parsing. It's usually JsonSyntaxException or JsonDataException\n            //        but method is going to fail on ANY exception.\n            //   2. An exception is thrown during reflection access. It's very unlikely yo happen unless something\n            //        modifies your field declarations (name, type, etc.) at the runtime.\n            this.mapper.map(ApplicationSettings.class, file);\n        } catch (final ConfigurationMappingException | IOException e) {\n            // Printing stack trace is helpful to know what went wrong:\n            e.printStackTrace();\n            // Generally when configuration loading fails and you don't have any kind of \"fallback\" values,\n            //   it may be a good idea to prevent application from starting.\n            final String shutdownMessage = (e.getCause() instanceof JsonSyntaxException || e.getCause() instanceof JsonDataException)\n                    ? \"There might be a syntax error somewhere. Closing...\"\n                    : (e.getCause() instanceof IllegalAccessException)\n                            ? \"Weird to see that happen, perhaps something modified a field declaration? Closing...\"\n                            : \"Something went wrong. Closing...\";\n            this.shutdown(shutdownMessage);\n        }\n        // Looks like everything loaded properly, you should be able to access your static fields now:\n        System.out.println(\"Is DEBUG enabled? \" + (ExampleConfig.DEBUG == true) ? \"yes.\" : \"no.\");\n        System.out.println(\"Is NULLABLE null? \" + (ExampleConfig.NULLABLE == null) ? \"yes.\" : \"no.\");\n    }\n}\n```\n\n\u003cbr /\u003e\n\n## Building (Linux)\n```shell\n# Cloning repository\n$ git clone https://github.com/Grabsky/configuration.git\n# Entering cloned repository\n$ cd ./configuration\n# Compiling and publishing to maven local\n$ ./gradlew clean test publishToMavenLocal\n```\n\n\u003cbr /\u003e\n\n## Contributing\nThis project is open for contributions. Help in regards of improving performance, adding new features or fixing bugs is greatly appreciated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrabsky%2Fconfiguration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrabsky%2Fconfiguration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrabsky%2Fconfiguration/lists"}