https://github.com/saveourtool/serialization-adapters
https://github.com/saveourtool/serialization-adapters
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/saveourtool/serialization-adapters
- Owner: saveourtool
- License: mit
- Created: 2022-01-12T18:18:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-21T10:04:47.000Z (about 4 years ago)
- Last Synced: 2025-04-10T12:50:17.600Z (about 1 year ago)
- Language: Kotlin
- Size: 130 KB
- Stars: 6
- Watchers: 5
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kotlin Serialization Adapters
Adapters and converters for different serialization types. For example: from JSON to CSV, from TOML to YML, from CSV to SARIF, etc.
You simply need to provide the mapping **schema** and kotlinx **serialization library** for it.
## Project's initial idea
Initially, we wanted simply to create a small tool that will be able to convert custom formats that have a support in [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization/tree/master/formats) to [SARIF](https://docs.oasis-open.org/sarif/sarif/v2.0/sarif-v2.0.html) format.
Later we thought that it can be useful for other developers to have a common adapter for different serialization types.
## Adding a custom format
If you would like to use this library as cli-app:
1) Implement `@Serializable` data class that will be used for deserialization of an input
2) Implement a subclass of `AdapterProxy`. Preferable way is to use `SarifAdapter` factory method, but if you need more granular control of functionality, you can extend classes directly.
3) Create a Service Provider Interface file `META-INF/services/org.cqfn.save.adapter.AdapterProxy`
In case you plan to have an adapter as a library:
1) Implement `@Serializable` data classes that will be used for deserialization and serialization of an input
2) ??? (set the INPUT and OUTPUT formats and proper libraries will be automatically added by the adapter)
3) Provide these classes to the `KxSerializationAdapter`
## Examples of usage
We have prepared some examples that can be found [here](https://github.com/analysis-dev/serialization-adapters/tree/main/examples).
## How it works:

## Running the cli application (stdin - stdout)
Prerequisites: Java.
1) Put the fat-jar with your custom type into the same directory with `save-adapters.jar`
2) Then write serialized representation of your data into app's stdin:
```bash
cat my-data.json | java -cp * org.cqfn.save.adapter.RunnerKt
```
## Running the cli application (file input - file output)
1) Put the `fat-jar` with your custom type into the same directory with `save-adapters.jar`
2) Run the following command to convert your file:
```bash
java -cp * org.cqfn.save.adapter.RunnerKt "/full/path/my-file-input" "/full/path/my-file-output.sarif"
```