{"id":24173285,"url":"https://github.com/sbespalov/cs-mapper","last_synced_at":"2026-05-15T05:03:59.789Z","repository":{"id":78394288,"uuid":"87135530","full_name":"sbespalov/cs-mapper","owner":"sbespalov","description":"Useful POJO mapper","archived":false,"fork":false,"pushed_at":"2017-11-07T09:58:33.000Z","size":278,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-30T15:09:26.308Z","etag":null,"topics":["beanmapper","dozer","dozermapper","dto","entity","jpa-entities","jpa-entity-model","plane-pojos","pojo","spring"],"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/sbespalov.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-04-04T01:02:32.000Z","updated_at":"2024-09-08T05:44:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"ce4d2f82-b2ab-44b3-9f18-8cfaea83b359","html_url":"https://github.com/sbespalov/cs-mapper","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sbespalov/cs-mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbespalov%2Fcs-mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbespalov%2Fcs-mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbespalov%2Fcs-mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbespalov%2Fcs-mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sbespalov","download_url":"https://codeload.github.com/sbespalov/cs-mapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sbespalov%2Fcs-mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33054454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-15T02:00:06.351Z","response_time":103,"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":["beanmapper","dozer","dozermapper","dto","entity","jpa-entities","jpa-entity-model","plane-pojos","pojo","spring"],"created_at":"2025-01-13T01:15:37.700Z","updated_at":"2026-05-15T05:03:59.780Z","avatar_url":"https://github.com/sbespalov.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introdution\n\nThere is a common view, that the **_DTO (Data Transfer Object)_**  is an anti-pattern, but **_CSMapper_** targets to dispel this prejudice.\n\nIf we imagine a standard **_JavaEE_** application, then, as a rule, it has a \"Layered architecture\" with an API on top (which is **_Presensation Layer_**), and JPA domain model at the bottom (which is **_Persistence Layer_**). Also we can say that API parameters depends on **_JPA Entity Model_** at most, and is a kind of its projection. So here is the dummy copy paste come from, which is the reason that makes DTO called ~~antipattern~~. But this copy paste problem can be very simply solved, which is what the **_CSMapper_** makes, and turn the DTO back into a very cool pattern.\n\nWe can divide the solution into three parts:\n* generate plane POJOs, based on JPA Entity model;\n* construct API parameters with those plane POJOs;\n* merge values from Entity to POJO and vice versa;\n\nThat's it! \n\nThere are usage examples below, which will help to make some details clearer.\n\n# Usage\n\nAll features, that **_CSMapper_** provides, can be used out of the box with well known Java technology stack, such as Spring and Hibernate. The configuration is very simple and takes about 15 minutes:\n\n#### 1. Generate **_JPA Entity_** based **_POJOs_**\n\nThe code generation process occurs during the project build. This is done using the Maven plugin:\n\n```xml\n\u003cbuild\u003e\n    \u003cplugins\u003e\n        \u003cplugin\u003e\n            \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n            \u003cartifactId\u003emaven-javadoc-plugin\u003c/artifactId\u003e\n            \u003cexecutions\u003e\n                \u003cexecution\u003e\n                    \u003cid\u003edomaindto\u003c/id\u003e\n                    \u003cphase\u003egenerate-sources\u003c/phase\u003e\n                    \u003cgoals\u003e\n                        \u003cgoal\u003ejavadoc\u003c/goal\u003e\n                    \u003c/goals\u003e\n                    \u003cconfiguration\u003e\n                        \u003cdoclet\u003eorg.carlspring.beans.utils.doclet.DomainDtoDoclet\u003c/doclet\u003e\n                        \u003csubpackages\u003eorg.carlspring.beans.mapper.examples.domain\u003c/subpackages\u003e\n                        \u003cdocletArtifacts\u003e\n                            \u003cdocletArtifact\u003e\n                                \u003cgroupId\u003eorg.carlspring.beans\u003c/groupId\u003e\n                                \u003cartifactId\u003ecs-mapper-utils\u003c/artifactId\u003e\n                                \u003cversion\u003e1.0\u003c/version\u003e\n                            \u003c/docletArtifact\u003e\n                        \u003c/docletArtifacts\u003e\n                        \u003cadditionalparam\u003e\n                            -basepackage\n                            org.carlspring.beans.mapper.examples.domain\n                            -outputfolder\n                            ${project.build.directory}/generated-sources\n                            -prefexedproperties\n                            id,name\n                        \u003c/additionalparam\u003e\n                        \u003cuseStandardDocletOptions\u003efalse\u003c/useStandardDocletOptions\u003e\n                        \u003cmaxmemory\u003e512\u003c/maxmemory\u003e\n                    \u003c/configuration\u003e\n                \u003c/execution\u003e\n            \u003c/executions\u003e\n        \u003c/plugin\u003e\n        \u003cplugin\u003e\n            \u003cgroupId\u003eorg.codehaus.mojo\u003c/groupId\u003e\n            \u003cartifactId\u003ebuild-helper-maven-plugin\u003c/artifactId\u003e\n            \u003cexecutions\u003e\n                \u003cexecution\u003e\n                    \u003cid\u003eadd-source\u003c/id\u003e\n                    \u003cphase\u003egenerate-sources\u003c/phase\u003e\n                    \u003cgoals\u003e\n                        \u003cgoal\u003eadd-source\u003c/goal\u003e\n                    \u003c/goals\u003e\n                    \u003cconfiguration\u003e\n                        \u003csources\u003e\n                            \u003csource\u003e${project.build.directory}/generated-sources\u003c/source\u003e\n                        \u003c/sources\u003e\n                    \u003c/configuration\u003e\n                \u003c/execution\u003e\n            \u003c/executions\u003e\n        \u003c/plugin\u003e\n    \u003c/plugins\u003e\n\u003c/build\u003e\n```\n\u003e Note that this configuration must be placed in module, that contains JPA Entities\n\nWe using the `DomainDtoDoclet` to get **_JPA Entities_** metadata from `.java` sources. Also there will be a dedicated `cs-mapper-plugin` instead of `maven-javadoc-plugin` and `build-helper-maven-plugin` in future versions.\n\n#### 2. **_BeanMapper_** instace configuration\n\n**_BeanMapper_** can be easily configured inside **_Spring Application Context_** using **_BeanMapperFactoryBean_** like this:\n\n```java\n@Configuration\npublic class AppConfiguration {\n\n   ...\n\n    @Bean\n    public BeanMapperFactoryBean beanMapper(EntityManagerFactory emf)\n    {\n        BeanMapperFactoryBean result = new BeanMapperFactoryBean(emf);\n        result.setMappedClasses(Arrays.asList(DomainDtoClasses.domainDtoClasses));\n        result.setPackagesToScan(\"your.application.package.name.api.dto\");\n        return result;\n    }\n}\n\n```\n\n#### 3. Merge POJOs with **_JPA Entities_** with **_BeanMapper_**\n\n```java\n@Component\npublic class SampleApiService {\n\n    @PersistenceContext\n    private EntityManager entityManager;\n\n    @Autowired\n    private BeanMapper beanMapper;\n\n    public PetStoreReadDto getPetStore(Long petStoreId) {\n        PetStoreEntity petStoreEntity = entityManager.find(PetStoreEntity.class, petStoreId);  \n        return (PetStoreReadDto) beanMapper.convertObject(petStoreEntity, PetStoreReadDto.class);\n    }\n\n}\n```\n\n## Common Use Cases\n\nUsage examples can be found [here](https://github.com/sbespalov/cs-mapper/tree/master/cs-mapper-examples)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbespalov%2Fcs-mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsbespalov%2Fcs-mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsbespalov%2Fcs-mapper/lists"}