Skip to content

Serialization

Module serialization

This module holds serialization utilities.

Install the Dependency

This module is not meant to be used directly. You should include an Adapter implementing this feature (as serialization_dsl_json) in order to parse/serialize data.

1
2
3
4
5
repositories {
    mavenCentral()
}

implementation("com.hexagonkt:serialization:$hexagonVersion")
1
2
3
4
5
<dependency>
  <groupId>com.hexagonkt</groupId>
  <artifactId>serialization</artifactId>
  <version>$hexagonVersion</version>
</dependency>

Defined Ports

TODO Document module exposed ports: * SerializationFormat

Serialization

The core module has utilities to serialize/parse data classes to JSON and YAML. Read the following snippet for details:

1
2
3
4
5
6
7
8
SerializationManager.formats = setOf(format) // Loads the serialization format
val jason = Person("Jason", "Jackson", LocalDate.of(1989, 12, 31))

val jasonJson = personToMap(jason).serialize(format)
val parsedJason = mapToPerson(jasonJson.parseMap(format))

assertEquals(parsedJason, jason)
assert(jason !== parsedJason)

Package com.hexagonkt.serialization

Parse/serialize data in different formats to class instances.