{"id":22750075,"url":"https://github.com/pwall567/kjson-cloud-event","last_synced_at":"2026-05-03T02:44:55.730Z","repository":{"id":65509300,"uuid":"496025982","full_name":"pwall567/kjson-cloud-event","owner":"pwall567","description":"Kotlin implementation of CloudEvents specification (v1)","archived":false,"fork":false,"pushed_at":"2024-01-09T02:07:32.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-21T08:56:24.422Z","etag":null,"topics":["event","json","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pwall567.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-05-25T00:09:40.000Z","updated_at":"2022-06-23T14:31:57.000Z","dependencies_parsed_at":"2023-10-16T03:55:26.099Z","dependency_job_id":"874e910d-e27d-42b2-be7b-94b61bac2c64","html_url":"https://github.com/pwall567/kjson-cloud-event","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/pwall567/kjson-cloud-event","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-cloud-event","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-cloud-event/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-cloud-event/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-cloud-event/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pwall567","download_url":"https://codeload.github.com/pwall567/kjson-cloud-event/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pwall567%2Fkjson-cloud-event/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32556771,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T00:31:16.350Z","status":"online","status_checked_at":"2026-05-03T02:00:09.297Z","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":["event","json","kotlin"],"created_at":"2024-12-11T04:12:16.625Z","updated_at":"2026-05-03T02:44:55.716Z","avatar_url":"https://github.com/pwall567.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kjson-cloud-event\n\n[![Build Status](https://travis-ci.com/pwall567/kjson-cloud-event.svg?branch=main)](https://app.travis-ci.com/github/pwall567/kjson-cloud-event)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Kotlin](https://img.shields.io/static/v1?label=Kotlin\u0026message=v1.8.22\u0026color=7f52ff\u0026logo=kotlin\u0026logoColor=7f52ff)](https://github.com/JetBrains/kotlin/releases/tag/v1.8.22)\n[![Maven Central](https://img.shields.io/maven-central/v/io.kjson/kjson-cloud-event?label=Maven%20Central)](https://search.maven.org/search?q=g:%22io.kjson%22%20AND%20a:%22kjson-cloud-event%22)\n\nKotlin implementation of CloudEvents specification (v1)\n\n## Background\n\nThe [CloudEvents](https://cloudevents.io/) specification is becoming widely accepted as a means of describing events\npassed between processes.\nThe `kjson-cloud-event` library provides a simple implementation of the CloudEvents structure in Kotlin.\n\nMany uses (possibly the vast majority of uses) of CloudEvents will use JSON as the external representation of the event.\nThe [specification](https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md) sets out how events are to be\nserialized, and in most cases, any general-purpose JSON library should be able to convert the events correctly. \n\nThe only problems arise with the use of\n[Extension Context Attributes](https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#extension-context-attributes).\nThe CloudEvents specification requires such attributes to be included in the JSON envelope of the event, and that means\nthat the JSON library must be provided with custom serialization and deserialization configuration in order to handle\nthese events.\n\nThe `kjson-cloud-event` library was created with the [`kjson`](https://github.com/pwall567/kjson) library in mind, but\nthe event classes from this library should also be usable in conjunction with any of the other popular JSON libraries.\nThe library provides two implementations of the CloudEvents specification:\n\n- [`CloudEvent`](#cloudevent): this handles the simple case without Extension Context Attributes, and events using this\nclass may be serialized and deserialized without additional configuration.\n- [`CloudEventExt`](#cloudeventext): this allows Extension Context Attributes, but this requires custom serialization\nand deserialization to be used.\nThe library includes functions to perform this custom serialization and deserialization when using `kjson`.\n\n## `CloudEvent`\n\nCloud Events that do not require the use of Extension Context Attributes can use the data class `CloudEvent`.\nThis is a generic class, parameterized with the type of the data payload, and it has the great virtue of simplicity.\n\nFor example:\n```kotlin\n    val accountOpen = AccountOpen(accountId = newAccountId, name = customerName)\n    val cloudEvent = CloudEvent(\n        id = UUID.randomUUID(),\n        source = eventSource,\n        type = \"com.example.accounts.open\",\n        subject = accountOpen.accountId,\n        time = OffsetDateTime.now(),\n        data = accountOpen,\n    )\n```\nwill create an object of type `CloudEvent\u003cAccountOpen\u003e`.\n\n## `CloudEventExt`\n\nCloud Events that use Extension Context Attributes can use the data class `CloudEventExt`.\nThis is a generic class, parameterized with both the type of the data payload, and the type of the extensions object.\n\nAs an example, suppose that two additional Extension Context Attributes were required: a security principal id in the\nform of a UUID, and a token in the form of an opaque string.\nTo hold these attributes, a data class may be defined:\n```kotlin\ndata class Extension(val principalId: UUID, val token: String)\n```\n\nThen, a `CloudEventExt` instance may be created as follows:\n```kotlin\n    val accountOpen = AccountOpen(accountId = newAccountId, name = customerName)\n    val cloudEvent = CloudEventExt(\n        id = UUID.randomUUID(),\n        source = eventSource,\n        type = \"com.example.accounts.open\",\n        subject = accountOpen.accountId,\n        time = OffsetDateTime.now(),\n        extension = Extension(currentPrincipal, token1),\n        data = accountOpen,\n    )\n```\nThis will create an object of type `CloudEventExt\u003cAccountOpen, Extension\u003e`, and when serialized with the appropriate\nconfiguration, the `principalId` and `token` attributes will appear in the envelope of the event.\n\nAlternatively, a `Map` may be used to hold the Extension Context Attributes.\nThe following example creates a `CloudEventExt` with the same external representation as the above:\n```kotlin\n    val accountOpen = AccountOpen(accountId = newAccountId, name = customerName)\n    val cloudEvent = CloudEventExt(\n        id = UUID.randomUUID(),\n        source = eventSource,\n        type = \"com.example.accounts.open\",\n        subject = accountOpen.accountId,\n        time = OffsetDateTime.now(),\n        extension = mapOf(\"principalId\" to currentPrincipal.toString(), \"token\" to token1),\n        data = accountOpen,\n    )\n```\nThe object type in this case will be `CloudEventExt\u003cAccountOpen, Map\u003cString, String\u003e\u003e` (the key of the map must be of\ntype `String`; the value may be of any type, but if mixed types are used, the deserialization functions will not have\nsufficient information to determine the target type of, say, a `UUID`).\n\n## Serialization and Deserialization\n\nThe `CloudEvent` objects will serialize correctly using the [`kjson`](https://github.com/pwall567/kjson) library,\nand most other JSON libraries should handle the class without problems.\n\nThe only difficulties arise when using the `CloudEventExt` class.\nEvents created using this class will require configuration like the following to be added:\n```kotlin\n    val config = JSONConfig {\n        addCloudEventExtToJSON\u003cAccountOpen, Extension\u003e()\n        addCloudEventExtFromJSON\u003cAccountOpen, Extension\u003e()\n    }\n```\nThen, this `config` object must be supplied to the `parseJSON()` or `stringifyJSON()` functions that handle these\nobjects:\n```kotlin\n    val event = data.parseJSON\u003cCloudEventExt\u003cAccountOpen, Extension\u003e\u003e(config)\n```\n\nThe custom deserialization may be combined with [`kjson`](https://github.com/pwall567/kjson) polymorphic\ndeserialization of the cloud event payload.\nSee the\n[`kjson` Custom Serialization and Deserialization Guide](https://github.com/pwall567/kjson/blob/main/CUSTOM.md#fromjsonpolymorphic)\nfor more information.\n\nOther JSON libraries will probably have similar functionality; consult the documentation for the library for further\ninformation.\n\n## Dependency Specification\n\nThe latest version of the library is 1.10, and it may be obtained from the Maven Central repository.\n\n**IMPORTANT:** The `JSONCloudEventConverter` class (custom serialization of the `CloudEventExt` class for `kjson`) in\nthis version of the library requires `kjson` version 7.1 or greater.\n\n### Maven\n```xml\n    \u003cdependency\u003e\n      \u003cgroupId\u003eio.kjson\u003c/groupId\u003e\n      \u003cartifactId\u003ekjson-cloud-event\u003c/artifactId\u003e\n      \u003cversion\u003e1.10\u003c/version\u003e\n    \u003c/dependency\u003e\n```\n### Gradle\n```groovy\n    implementation 'io.kjson:kjson-cloud-event:1.10'\n```\n### Gradle (kts)\n```kotlin\n    implementation(\"io.kjson:kjson-cloud-event:1.10\")\n```\n\nPeter Wall\n\n2023-10-15\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Fkjson-cloud-event","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpwall567%2Fkjson-cloud-event","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpwall567%2Fkjson-cloud-event/lists"}