{"id":18521720,"url":"https://github.com/transferwise/terra","last_synced_at":"2025-04-09T09:33:21.325Z","repository":{"id":41117575,"uuid":"83810121","full_name":"transferwise/terra","owner":"transferwise","description":"A minimalistic library for object hydration. Useful for data to object reconstruction mechanics.","archived":false,"fork":false,"pushed_at":"2023-04-07T01:25:50.000Z","size":61,"stargazers_count":1,"open_issues_count":3,"forks_count":5,"subscribers_count":113,"default_branch":"master","last_synced_at":"2025-03-24T04:43:25.782Z","etag":null,"topics":["hydration","persistence"],"latest_commit_sha":null,"homepage":null,"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/transferwise.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-03-03T15:03:01.000Z","updated_at":"2020-09-14T10:13:47.000Z","dependencies_parsed_at":"2024-11-06T17:35:00.075Z","dependency_job_id":"71f63780-978d-4898-bd46-617ce186b4cc","html_url":"https://github.com/transferwise/terra","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transferwise%2Fterra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transferwise%2Fterra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transferwise%2Fterra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/transferwise%2Fterra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/transferwise","download_url":"https://codeload.github.com/transferwise/terra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248012862,"owners_count":21033254,"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":["hydration","persistence"],"created_at":"2024-11-06T17:27:12.822Z","updated_at":"2025-04-09T09:33:20.630Z","avatar_url":"https://github.com/transferwise.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terra [![CircleCI](https://circleci.com/gh/transferwise/terra/tree/master.svg?style=shield)](https://circleci.com/gh/transferwise/terra/tree/master)\n\nA minimalistic library for _object hydration_. Useful for data to object reconstruction mechanics.\n\n## Installation\n\nJust add the following configuration to your `build.gradle` file\n\n```gradle\nallprojects {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n\ndependencies {\n    compile 'com.github.transferwise:terra:1.0.0'\n}\n```\n\n## Usage\n\nGiven a value object like the following\n\n```java\nimport java.util.regex.Pattern;\n\nclass Email {\n    private static final Pattern FORMAT = \n        Pattern.compile(\"^[A-Z0-9._%-]+@[A-Z0-9.-]+\\\\.[A-Z]{2,6}$\", Pattern.CASE_INSENSITIVE);\n    \n    private final String value;\n    \n    Email(String aValue) {\n        if (!FORMAT.matcher(aValue).matches()) {\n            throw new RuntimeException(\"Email \" + aValue + \" is incorrect\");\n        }\n        value = aValue;\n    }\n    \n    public String getValue() {\n        return value;\n    }\n}\n```\n\nImagine you'd want to rebuild the object, bypassing the constructor validation.\n\n```java\n\nimport static com.transferwise.terra.Terra.hydrate;\n\nclass Example {\n    public static void main(String[] args) {\n        Email e = hydrate(Email.class, \"value\", \"not+valid+email@example.com\");\n        \n        System.out.println(e.getValue());\n    }\n}\n```\n\n#### Why would we disable the constructor?\n\nThis is a very common behaviour when you reconstruct objects from data stored in your persistence mechanism. The validation rules usually live in the write model, not in the read model. Business constraints change all the time and you might end up with data that does not follow these rules at a given moment. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftransferwise%2Fterra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftransferwise%2Fterra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftransferwise%2Fterra/lists"}