{"id":19486532,"url":"https://github.com/phxql/jackson-polymorphic-deserialization","last_synced_at":"2025-07-30T03:42:30.189Z","repository":{"id":54416880,"uuid":"226112086","full_name":"phxql/jackson-polymorphic-deserialization","owner":"phxql","description":"Small showcase for Jacksons polymorphic deserialization feature","archived":false,"fork":false,"pushed_at":"2023-04-02T10:57:25.000Z","size":60,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-25T18:39:27.356Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phxql.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-12-05T13:46:27.000Z","updated_at":"2022-11-16T10:40:43.000Z","dependencies_parsed_at":"2025-04-25T18:49:00.335Z","dependency_job_id":null,"html_url":"https://github.com/phxql/jackson-polymorphic-deserialization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/phxql/jackson-polymorphic-deserialization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phxql%2Fjackson-polymorphic-deserialization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phxql%2Fjackson-polymorphic-deserialization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phxql%2Fjackson-polymorphic-deserialization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phxql%2Fjackson-polymorphic-deserialization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phxql","download_url":"https://codeload.github.com/phxql/jackson-polymorphic-deserialization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phxql%2Fjackson-polymorphic-deserialization/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267804105,"owners_count":24146537,"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-07-30T02:00:09.044Z","response_time":70,"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":[],"created_at":"2024-11-10T20:38:08.950Z","updated_at":"2025-07-30T03:42:30.134Z","avatar_url":"https://github.com/phxql.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Jackson's Polymorphic Deserialization\n\nThis repo contains an abstract class `Animal`, which has two subtypes: `Cat` (with a boolean flag `canMeow`) and a `Dog`\n(with a boolean flag `canBark`).\n\nSerializing an object of `Cat` or `Dog` is no problem, because Jackson can find out the actual class at runtime. Problems\nstart when trying to deserialize the JSON.\n\nWell,\n\n```\nCat cat2 = mapper.readValue(catJson, Cat.class);\n```\n\nworks, because of the `Cat.class` in the method call. But what if you want to read a JSON, which could contain a `Dog` or\na `Cat`?\n\n```\nAnimal dog2 = mapper.readValue(dogJson, Animal.class);\n```\n\nFor that you can use `@JsonTypeInfo`. Take a look at the [Animal class](src/main/java/de/mkammerer/jpd/Animal.java).\n\nThe JSON result looks like this:\n\n```json\n{\n    \"type\" : \"cat\",\n    \"name\" : \"Ms. Cat\",\n    \"canMeow\" : true\n}\n```\n\n```json\n{\n    \"type\" : \"dog\",\n    \"name\" : \"Mr. Dog\",\n    \"canBark\" : true\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphxql%2Fjackson-polymorphic-deserialization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphxql%2Fjackson-polymorphic-deserialization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphxql%2Fjackson-polymorphic-deserialization/lists"}