{"id":16689572,"url":"https://github.com/sigpwned/jackson-modules-java-17-sealed-classes","last_synced_at":"2025-10-08T23:06:42.156Z","repository":{"id":65507917,"uuid":"517402618","full_name":"sigpwned/jackson-modules-java-17-sealed-classes","owner":"sigpwned","description":"Simplified polymorphic de/serialization of Java 17 sealed classes for Jackson","archived":false,"fork":false,"pushed_at":"2025-10-01T07:02:03.000Z","size":131,"stargazers_count":23,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-08T23:06:38.464Z","etag":null,"topics":["jackson","java17","json","sealed-class"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sigpwned.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-24T18:16:28.000Z","updated_at":"2025-09-16T11:01:39.000Z","dependencies_parsed_at":"2025-02-16T05:32:44.178Z","dependency_job_id":"cf8f8c2b-f256-4246-922d-7eed70a9e0b4","html_url":"https://github.com/sigpwned/jackson-modules-java-17-sealed-classes","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/sigpwned/jackson-modules-java-17-sealed-classes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fjackson-modules-java-17-sealed-classes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fjackson-modules-java-17-sealed-classes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fjackson-modules-java-17-sealed-classes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fjackson-modules-java-17-sealed-classes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sigpwned","download_url":"https://codeload.github.com/sigpwned/jackson-modules-java-17-sealed-classes/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sigpwned%2Fjackson-modules-java-17-sealed-classes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000729,"owners_count":26082862,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["jackson","java17","json","sealed-class"],"created_at":"2024-10-12T15:48:38.201Z","updated_at":"2025-10-08T23:06:42.149Z","avatar_url":"https://github.com/sigpwned.png","language":"Java","readme":"# Jackson Modules - Java 17 Sealed Classes [![tests](https://github.com/sigpwned/jackson-modules-java-17-sealed-classes/actions/workflows/tests.yml/badge.svg)](https://github.com/sigpwned/jackson-modules-java-17-sealed-classes/actions/workflows/tests.yml) ![Maven Central Version](https://img.shields.io/maven-central/v/com.sigpwned/jackson-modules-java17-sealed-classes)\n\n`jackson-modules-java17-sealed-classes` is a [Jackson](https://github.com/FasterXML/jackson) module that adds improved support for polymorphic serialization of Java 17 sealed classes.\n\nThis implementation was [merged](https://github.com/FasterXML/jackson-databind/pull/5025) upstream into jackson-databind proper for [release 3.0.0-rc2](https://cowtowncoder.medium.com/jackson-3-0-0-rc2-minor-update-593306f89e2c#10b4). So as of Jackson 3.x, this module is now obsolete! I will continue to maintain for Jackson 2.x.\n\n## Goals\n\n* Add improved support for polymorphic serialization of Java 17 sealed classes\n\n## Non-Goals\n\n* Change any other aspects of Jackson serialization\n\n## Usage\n\nThe versioning of this project is aligned with Jackson versioning. (For example, if your project is using Jackson 2.18.2, then you should add the latest version of 2.18.2.x available in Maven Central to your POM file.)\n\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.sigpwned\u003c/groupId\u003e\n        \u003cartifactId\u003ejackson-modules-java17-sealed-classes\u003c/artifactId\u003e\n        \u003cversion\u003e2.19.0.0\u003c/version\u003e\n    \u003c/dependency\u003e\n\nTo activate this feature, users must register the `Jdk17SealedClassesModule` module with the `ObjectMapper`. Simply include this library, and add the module to the `ObjectMapper`:\n\n    ObjectMapper mapper=new ObjectMapper().registerModule(new Jdk17SealedClassesModule());\n\nWithout this module, sealed classes must use the `@JsonSubTypes` annotation for [polymorphic serialization](https://www.baeldung.com/jackson-annotations), just like any other class:\n\n    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = \"type\")\n    @JsonSubTypes({\n        @JsonSubTypes.Type(value=AlphaSealedExample.class, name=\"alpha\"),\n        @JsonSubTypes.Type(value=BravoSealedExample.class, name=\"bravo\")})\n    public sealed class SealedExample permits AlphaSealedExample, BravoSealedExample {\n    }\n    \n    public final class AlphaSealedExample extends SealedExample {\n        private String alpha;\n        \n        public String getAlpha() {\n            return alpha;\n        }\n        \n        public void setAlpha(String alpha) {\n            this.alpha = alpha;\n        }\n        \n        public SealedExample withAlpha(String alpha) {\n            setAlpha(alpha);\n            return this;\n        }\n    }\n    \n    public final class BravoSealedExample extends SealedExample {\n        private String bravo;\n        \n        public String getBravo() {\n            return bravo;\n        }\n        \n        public void setBravo(String bravo) {\n            this.bravo = bravo;\n        }\n        \n        public SealedExample withBravo(String bravo) {\n            setBravo(bravo);\n            return this;\n        }\n    }\n\nHowever, this is repetitive, since sealed classes already enumerate their subtypes explicitly. With this module, users get polymorphic serialization of sealed classes by using only the `@JsonTypeInfo` annotation on the parent sealed class. Users can also add `@JsonTypeName` to child classes to customize subtype naming, but it is not required.\n\n    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = \"type\")\n    public sealed class SealedExample permits AlphaSealedExample, BravoSealedExample {\n    }\n    \n    @JsonTypeName(\"alpha\")\n    public final class AlphaSealedExample extends SealedExample {\n        private String alpha;\n        \n        public String getAlpha() {\n            return alpha;\n        }\n        \n        public void setAlpha(String alpha) {\n            this.alpha = alpha;\n        }\n        \n        public SealedExample withAlpha(String alpha) {\n            setAlpha(alpha);\n            return this;\n        }\n    }\n    \n    @JsonTypeName(\"bravo\")\n    public final class BravoSealedExample extends SealedExample {\n        private String bravo;\n        \n        public String getBravo() {\n            return bravo;\n        }\n        \n        public void setBravo(String bravo) {\n            this.bravo = bravo;\n        }\n        \n        public SealedExample withBravo(String bravo) {\n            setBravo(bravo);\n            return this;\n        }\n    }\n    \nEither example would result in the following JSON:\n\n    serialize(new AlphaSealedExample().withAlpha(\"value\")) → {\"type\":\"alpha\",\"alpha\":\"value\"}\n\n    deserialize({\"type\":\"alpha\",\"alpha\":\"value\"}) → new AlphaSealedExample().withAlpha(\"value\")\n    \n    serialize(new BravoSealedExample().withBravo(\"value\")) → {\"type\":\"bravo\",\"bravo\":\"value\"}\n    \n    deserialize({\"type\":\"bravo\",\"bravo\":\"value\"}) → new BravoSealedExample().withBravo(\"value\")\n    \n## Acknowledgements\n\nMany thanks to [@shartte](https://github.com/shartte) for his work on [FasterXML/jackson-module-kotlin#239](https://github.com/FasterXML/jackson-module-kotlin/issues/239), where he implemented a very similar feature for Kotlin. And of course, thank you to [@cowtowncoder](https://github.com/cowtowncoder) for maintaining the excellent [FasterXML/jackson](https://github.com/FasterXML/jackson) library for all this time.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigpwned%2Fjackson-modules-java-17-sealed-classes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsigpwned%2Fjackson-modules-java-17-sealed-classes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsigpwned%2Fjackson-modules-java-17-sealed-classes/lists"}