{"id":13565364,"url":"https://github.com/jcustenborder/connect-utils","last_synced_at":"2025-04-10T17:13:43.547Z","repository":{"id":9487534,"uuid":"62282525","full_name":"jcustenborder/connect-utils","owner":"jcustenborder","description":"Utility project for working with Kafka Connect.","archived":false,"fork":false,"pushed_at":"2024-07-31T07:56:15.000Z","size":986,"stargazers_count":34,"open_issues_count":22,"forks_count":26,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-24T15:01:35.140Z","etag":null,"topics":["conversion","kafka","kafka-connect","parsing","schema"],"latest_commit_sha":null,"homepage":"http://confluent.io","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/jcustenborder.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}},"created_at":"2016-06-30T05:40:10.000Z","updated_at":"2025-03-11T02:32:04.000Z","dependencies_parsed_at":"2024-10-27T00:53:40.089Z","dependency_job_id":null,"html_url":"https://github.com/jcustenborder/connect-utils","commit_stats":null,"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcustenborder%2Fconnect-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcustenborder%2Fconnect-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcustenborder%2Fconnect-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcustenborder%2Fconnect-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcustenborder","download_url":"https://codeload.github.com/jcustenborder/connect-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248261913,"owners_count":21074225,"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":["conversion","kafka","kafka-connect","parsing","schema"],"created_at":"2024-08-01T13:01:45.452Z","updated_at":"2025-04-10T17:13:43.524Z","avatar_url":"https://github.com/jcustenborder.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# Overview\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.jcustenborder.kafka.connect/connect-utils/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.jcustenborder.kafka.connect/connect-utils)\n\nThe purpose of this library is to aid with conversions from strings to the proper Kafka Connect data types. Hopefully this library can be usedful in reducing the amount of mind numbing string parsing code.\n\n# Type Parsing\n\nThis section of code will help with conversions from strings to the proper Kafka Connect data types. Hopefully this library can be useful in reducing the amount of mind numbing string parsing code used\ntransform Strings to Integers. The current code supports nullable schemas. An exception will be thrown if a null is passed with a schema that is not optional.\n\n## Convert to a schema type\n\n```\nParser parser = new Parser();\nObject value = parser.parseString(Schema.BOOLEAN_SCHEMA, \"true\");\n```\n\n```\nParser parser = new Parser();\nObject value = parser.parseJson(Schema.BOOLEAN_SCHEMA, objectMapper.valueToTree(true));\n```\n\n## Nulls are supported too\n\n```\nParser parser = new Parser();\nObject value = parser.parseString(Schema.OPTIONAL_BOOLEAN_SCHEMA, null);\n```\n\n```\nParser parser = new Parser();\nObject value = parser.parseJson(Schema.OPTIONAL_BOOLEAN_SCHEMA, null);\n```\n\n## Schemas without optional set do not support nulls\n\nIf you pass in a null to a schema that is not optional, you're going to have a bad time.\n\n```\nParser parser = new Parser();\nObject value = parser.parseString(Schema.BOOLEAN_SCHEMA, null);\n```\n\n```\nParser parser = new Parser();\nObject value = parser.parseJson(Schema.BOOLEAN_SCHEMA, null);\n```\n\n## Register your own type converter or an alternate date format \n\n```\nParser parser = new Parser();\nparser.registerTypeParser(Timestamp.SCHEMA, new DateTypeConverter(TimeZone.getTimeZone(\"UTC\"), new SimpleDateFormat(\"yyyy-MM-dd' 'HH:mm:ss\")));\n```\n\n# Templating of Kafka Connect types.\n\nThere are several cases where you will want to route data to a different topic based on a field in your data. \n[StructTemplate](src/main/java/com/github/jcustenborder/kafka/connect/utils/template/StructTemplate.java) is available to \nassist you with this. It uses [FreeMarker](http://freemarker.org/) under the covers to allow you to apply templates to Connect Stucts. For example:\n\n```java\n// Setup the template once, maybe during start()\nStructTemplate template = new StructTemplate();\ntemplate.addTemplate(\"test\", \"${stringField}\");\n\n//Apply the template.\nSchema schema = SchemaBuilder.struct()\n    .name(\"TestStruct\")\n    .field(\"stringField\", Schema.STRING_SCHEMA)\n    .field(\"nullStringField\", Schema.OPTIONAL_STRING_SCHEMA)\n    .build();\n\nStruct struct = new Struct(schema);\nstruct.put(\"stringField\", \"TestValue\");\nString actual = this.structTemplate.execute(\"test\", this.struct);\n\n//actual == \"TestValue\"\n```\n\nYou can combine static strings with variables to do something like `database.${stringField}` which would yield `database.TestValue` \nusing the example above. \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcustenborder%2Fconnect-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcustenborder%2Fconnect-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcustenborder%2Fconnect-utils/lists"}