{"id":19210983,"url":"https://github.com/bowbahdoe/magic-bean","last_synced_at":"2025-04-06T22:06:58.880Z","repository":{"id":44733376,"uuid":"449906690","full_name":"bowbahdoe/magic-bean","owner":"bowbahdoe","description":"A very basic library which will generate getters and setters.","archived":false,"fork":false,"pushed_at":"2025-02-09T18:43:23.000Z","size":411,"stargazers_count":85,"open_issues_count":1,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-30T20:11:18.946Z","etag":null,"topics":["annotation-processor","code-generation","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bowbahdoe.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-01-20T00:58:58.000Z","updated_at":"2025-03-27T08:16:35.000Z","dependencies_parsed_at":"2024-11-09T13:40:17.849Z","dependency_job_id":"38db370d-a865-4f74-9578-0fa4929d9eeb","html_url":"https://github.com/bowbahdoe/magic-bean","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowbahdoe%2Fmagic-bean","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowbahdoe%2Fmagic-bean/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowbahdoe%2Fmagic-bean/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bowbahdoe%2Fmagic-bean/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bowbahdoe","download_url":"https://codeload.github.com/bowbahdoe/magic-bean/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247557767,"owners_count":20958047,"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":["annotation-processor","code-generation","java"],"created_at":"2024-11-09T13:40:04.513Z","updated_at":"2025-04-06T22:06:58.859Z","avatar_url":"https://github.com/bowbahdoe.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Magic Bean\n\n\u003cimg src=\"./logo.png\"\u003e\u003c/img\u003e\n\nA very basic library which will generate getters and setters.\n\nRequires Java 21+.\n\n### Maven\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003edev.mccue\u003c/groupId\u003e\n    \u003cartifactId\u003emagic-bean\u003c/artifactId\u003e\n    \u003cversion\u003e2025.02.09\u003c/version\u003e\n    \u003cscope\u003eprovided\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\n### Gradle\n\n```\ndependencies {\n    compileOnly(\"dev.mccue:magic-bean:2025.02.09\")\n    annotationProcessor(\"dev.mccue:magic-bean:2025.02.09\")\n}\n```\n\n\n## What this does\nThis uses an annotation processor to generate a class which can\nbe extended to automatically derive the boilerplate code for \n- getters and setters\n- equals and hashCode\n- toString\n- an all argument constructor\n\nThe primary goals of this library are\n1. Boilerplate reduction for code that needs \"dumb\" POJOs\n2. Demonstrate that annotation processors and source code \ngeneration aren't that scary\n3. Cover some of the use cases of [lombok](https://projectlombok.org/) without\n[the compiler hacking it does](https://github.com/projectlombok/lombok/issues/2681)\n\nThe non-goals of this library are\n1. To provide a tool which fits all use cases. (conflicts with goal #2)\n2. Provide a way to generate immutable value objects. Use [records](https://dev.java/learn/using-record-to-model-immutable-data/),\n[immutables](https://immutables.github.io/), or elbow grease for that.\n3. Support old Java versions.\n\n## Usage\n\n### Basic Example\n\n#### I receive\n```java\nimport dev.mccue.magicbean.MagicBean;\n\nimport java.util.List;\n\n@MagicBean\npublic final class Example extends ExampleBeanOps {\n    int x;\n    String name;\n    List\u003cString\u003e strs;\n}\n```\n\n#### You receive\n```java\nsealed abstract class ExampleBeanOps extends java.lang.Object permits Example {\n\n    private Example self() {\n        return (switch (this) { case Example __ -\u003e __; });\n    }\n\n    /**\n     * Get the current value for x.\n     */\n    public int getX() {\n        return self().x;\n    }\n\n    /**\n     * Set the current value for x.\n     */\n    public void setX(int x) {\n        self().x = x;\n    }\n\n    /**\n     * Get the current value for name.\n     */\n    public java.lang.String getName() {\n        return self().name;\n    }\n\n    /**\n     * Set the current value for name.\n     */\n    public void setName(java.lang.String name) {\n        self().name = name;\n    }\n\n    /**\n     * Get the current value for strs.\n     */\n    public java.util.List\u003cjava.lang.String\u003e getStrs() {\n        return self().strs;\n    }\n\n    /**\n     * Set the current value for strs.\n     */\n    public void setStrs(java.util.List\u003cjava.lang.String\u003e strs) {\n        self().strs = strs;\n    }\n\n}\n```\n\n### Complete Example\n\n#### I receive \n```java\nimport dev.mccue.magicbean.MagicBean;\n\nimport java.util.List;\n\n@MagicBean(\n        allArgsStaticFactory = true,\n        equalsAndHashCode = true,\n        toString_ = true\n)\npublic final class Example extends ExampleBeanOps {\n    int x;\n    String name;\n    List\u003cString\u003e strs;\n}\n```\n\n#### You receive\n```java \nsealed abstract class ExampleBeanOps extends java.lang.Object permits Example {\n\n    private Example self() {\n        return (switch (this) { case Example __ -\u003e __; });\n    }\n\n    /**\n     * Creates an instance of Example.\n     */\n    public static Example of(\n            int x,\n            java.lang.String name,\n            java.util.List\u003cjava.lang.String\u003e strs\n    ) {\n        var o = new Example();\n        o.setX(x);\n        o.setName(name);\n        o.setStrs(strs);\n        return o;\n    }\n\n    /**\n     * Get the current value for x.\n     */\n    public int getX() {\n        return self().x;\n    }\n\n    /**\n     * Set the current value for x.\n     */\n    public void setX(int x) {\n        self().x = x;\n    }\n\n    /**\n     * Get the current value for name.\n     */\n    public java.lang.String getName() {\n        return self().name;\n    }\n\n    /**\n     * Set the current value for name.\n     */\n    public void setName(java.lang.String name) {\n        self().name = name;\n    }\n\n    /**\n     * Get the current value for strs.\n     */\n    public java.util.List\u003cjava.lang.String\u003e getStrs() {\n        return self().strs;\n    }\n\n    /**\n     * Set the current value for strs.\n     */\n    public void setStrs(java.util.List\u003cjava.lang.String\u003e strs) {\n        self().strs = strs;\n    }\n\n    @Override\n    public boolean equals(Object o) {\n        if (o == null || !(o instanceof Example other)) {\n            return false;\n        }\n        else {\n            return java.util.Objects.equals(self().x, other.x) \u0026\u0026\n                   java.util.Objects.equals(self().name, other.name) \u0026\u0026\n                   java.util.Objects.equals(self().strs, other.strs);\n        }\n    }\n\n    @Override\n    public int hashCode() {\n        return java.util.Objects.hash(\n                self().x,\n                self().name,\n                self().strs\n        );\n    }\n\n    @Override\n    public String toString() {\n        return \"Example[\" + \"x=\" + self().x +\n               \", \" + \"name=\" + self().name +\n               \", \" + \"strs=\" + self().strs + \"]\";\n    }\n\n}\n```\n\n## Usage with frameworks\n### [JPA / Hibernate](./usage/jpa.md)\n### [Rife2](./usage/rife2.md)\n\n\n## Customizing\nThis library is just about 350 lines of Java contained within a single file.\nIf it doesn't do exactly what you want, feel free to make a PR or fork and\nmake your own edits.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowbahdoe%2Fmagic-bean","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbowbahdoe%2Fmagic-bean","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbowbahdoe%2Fmagic-bean/lists"}