{"id":27377966,"url":"https://github.com/jusexton/spring-expandable-fields-example","last_synced_at":"2025-07-06T16:03:49.488Z","repository":{"id":135725075,"uuid":"233514534","full_name":"jusexton/spring-expandable-fields-example","owner":"jusexton","description":"Example implementation of expandable objects with spring","archived":false,"fork":false,"pushed_at":"2020-02-03T19:51:22.000Z","size":66,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T13:09:06.701Z","etag":null,"topics":["example","spring-boot"],"latest_commit_sha":null,"homepage":"","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/jusexton.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}},"created_at":"2020-01-13T04:59:14.000Z","updated_at":"2020-02-03T19:51:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"65e60fa0-8e0d-4d20-99b2-6063c04ab41d","html_url":"https://github.com/jusexton/spring-expandable-fields-example","commit_stats":null,"previous_names":["jusexton/spring-expandable-fields-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jusexton/spring-expandable-fields-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fspring-expandable-fields-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fspring-expandable-fields-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fspring-expandable-fields-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fspring-expandable-fields-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jusexton","download_url":"https://codeload.github.com/jusexton/spring-expandable-fields-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jusexton%2Fspring-expandable-fields-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263931988,"owners_count":23531704,"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":["example","spring-boot"],"created_at":"2025-04-13T13:09:00.282Z","updated_at":"2025-07-06T16:03:49.466Z","avatar_url":"https://github.com/jusexton.png","language":"Java","readme":"# Spring Expandable Fields Example\nSometimes it will be beneficial to not allow your API consumers to \"drink from the fire hose of data\". Expandable entity fields can help.\n\n## In Action\n### The Models\nSome example domain models we will use for demonstration purposes\n#### Person\n```java\npublic class Person {\n    private String firstName;\n    private String lastName;\n    \n    @JsonExpandableField\n    private ContactInformation contactInformation;\n}\n```\n\n#### Contact Information\n```java\npublic class ContactInformation {\n    @JsonExpandableField\n    private Address address;\n    \n    @JsonExpandableField\n    private Phone phone;\n}\n```\n\n#### Address\n```java\npublic class Address {\n    private String street;\n    private String city;\n    private String state;\n    private String zip;\n}\n```\n\n#### Phone\n```java\npublic class Phone {\n    private String phoneNumber;\n    private PhoneType phoneType;\n}\n```\n\n#### Phone Type\n```java\npublic enum PhoneType {\n    HOME, CELL, WORK\n}\n```\n\n### The Requests\n\n#### localhost:8080/people\n```json\n{\n    \"firstName\": \"Justin\",\n    \"lastName\": \"Sexton\",\n    \"contactInformation\": {}\n}\n```\n\n#### localhost:8080/people?expand=contactinformation\n```json\n{\n    \"firstName\": \"Justin\",\n    \"lastName\": \"Sexton\",\n    \"contactInformation\": {\n        \"address\": {},\n        \"phone\": {}\n    }\n}\n```\n\n#### localhost:8080/people?expand=contactinformation.address\n```json\n{\n    \"firstName\": \"Justin\",\n    \"lastName\": \"Sexton\",\n    \"contactInformation\": {\n        \"address\": {\n            \"street\": \"1234 Street Drive\",\n            \"city\": \"City\",\n            \"state\": \"State\",\n            \"zip\": \"12345\"\n        },\n        \"phone\": {}\n    }\n}\n```\n\n#### localhost:8080/people?expand=contactinformation.address,contactinformation.phone\n```json\n{\n    \"firstName\": \"Justin\",\n    \"lastName\": \"Sexton\",\n    \"contactInformation\": {\n        \"address\": {\n            \"street\": \"1234 Street Drive\",\n            \"city\": \"City\",\n            \"state\": \"State\",\n            \"zip\": \"12345\"\n        },\n        \"phone\": {\n            \"phoneNumber\": \"1234567890\",\n            \"phoneType\": \"CELL\"\n        }\n    }\n}\n```\n\n## Troubles Serializing Map\nCurrenty when serializing a map, there is no way to distinguish map entries as expandable or not, so all entries will still be serialized. It is advised to convert the map to an object that makes use of the custom expandable annotations.\n\nHeres a useful link for converting maps to a POJO object. https://stackoverflow.com/questions/25447611/how-to-deserialize-a-mapstring-object-into-pojo\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjusexton%2Fspring-expandable-fields-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjusexton%2Fspring-expandable-fields-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjusexton%2Fspring-expandable-fields-example/lists"}