File tree 6 files changed +42
-6
lines changed
main/kotlin/earth/adi/typeid
test/kotlin/earth/adi/typeid 6 files changed +42
-6
lines changed Original file line number Diff line number Diff line change 1
1
# typeid-kotlin
2
2
![ Build Status] ( https://github.com/aleris/typeid-kotlin/actions/workflows/build-on-push.yml/badge.svg )
3
- ![ Current Version] ( https://img.shields.io/badge/Version-0.0.8 -blue )
3
+ ![ Current Version] ( https://img.shields.io/badge/Version-0.0.9 -blue )
4
4
5
5
6
6
## A Kotlin implementation of [ TypeID] ( https://github.com/jetpack-io/typeid ) .
@@ -25,14 +25,14 @@ To use with Maven:
25
25
<dependency >
26
26
<groupId >earth.adi</groupId >
27
27
<artifactId >typeid-kotlin</artifactId >
28
- <version >0.0.8 </version >
28
+ <version >0.0.9 </version >
29
29
</dependency >
30
30
```
31
31
32
32
To use via Gradle:
33
33
34
34
``` kotlin
35
- implementation(" earth.adi:typeid-kotlin:0.0.8 " )
35
+ implementation(" earth.adi:typeid-kotlin:0.0.9 " )
36
36
```
37
37
38
38
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ plugins {
14
14
15
15
group = " earth.adi"
16
16
17
- version = " 0.0.8 "
17
+ version = " 0.0.9 "
18
18
19
19
repositories { mavenCentral() }
20
20
@@ -159,6 +159,7 @@ tasks.publish { dependsOn(tasks.dokkaHtml) }
159
159
160
160
jreleaser {
161
161
project {
162
+ name.set(mavenArtifactId)
162
163
description.set(mavenArtifactDescription)
163
164
authors.set(arrayListOf (" aleris" ))
164
165
license.set(" Apache-2.0" )
Original file line number Diff line number Diff line change 1
1
package earth.adi.typeid
2
2
3
3
import earth.adi.typeid.codec.Codec
4
+ import java.io.Serializable
4
5
import java.util.UUID
5
6
6
7
/* *
@@ -10,7 +11,7 @@ import java.util.UUID
10
11
* @property prefix the prefix of the identifier
11
12
* @property uuid the uuid of the identifier
12
13
*/
13
- data class RawId (val prefix : String , val uuid : UUID ) {
14
+ data class RawId (val prefix : String , val uuid : UUID ) : Serializable {
14
15
init {
15
16
Codec .requireValidPrefix(prefix)
16
17
}
Original file line number Diff line number Diff line change 1
1
package earth.adi.typeid
2
2
3
+ import java.io.Serializable
4
+
3
5
/* * Typed prefix for a type id. */
4
- data class TypedPrefix <TEntity >(val prefix : String )
6
+ data class TypedPrefix <TEntity >(val prefix : String ) : Serializable
Original file line number Diff line number Diff line change 1
1
package earth.adi.typeid
2
2
3
+ import java.io.ByteArrayOutputStream
4
+ import java.io.ObjectInputStream
5
+ import java.io.ObjectOutputStream
3
6
import java.util.*
4
7
import org.assertj.core.api.Assertions.assertThat
5
8
import org.assertj.core.api.Assertions.assertThatThrownBy
@@ -30,4 +33,17 @@ class IdTest {
30
33
val id = Id <String >(TypedPrefix (" user" ), uuid)
31
34
assertThat(id.uuid).isEqualTo(uuid)
32
35
}
36
+
37
+ @Test
38
+ fun `test serialization deserialization` () {
39
+ val uuid = UUID .fromString(" 00000000-0000-0000-0000-000000000000" )
40
+ val id = Id <String >(TypedPrefix (" user" ), uuid)
41
+ ByteArrayOutputStream ().use { outputStream ->
42
+ ObjectOutputStream (outputStream).writeObject(id)
43
+ ObjectInputStream (outputStream.toByteArray().inputStream()).use {
44
+ @Suppress(" UNCHECKED_CAST" ) val deserializedId = it.readObject() as Id <String >
45
+ assertThat(deserializedId).isEqualTo(id)
46
+ }
47
+ }
48
+ }
33
49
}
Original file line number Diff line number Diff line change 1
1
package earth.adi.typeid
2
2
3
+ import java.io.ByteArrayOutputStream
4
+ import java.io.ObjectInputStream
5
+ import java.io.ObjectOutputStream
3
6
import java.util.*
4
7
import org.assertj.core.api.Assertions.assertThat
5
8
import org.junit.jupiter.api.Assertions.*
@@ -17,4 +20,17 @@ class RawIdTest {
17
20
val uuid = UUID .randomUUID()
18
21
assertThat(RawId (" prefix" , uuid).uuid).isEqualTo(uuid)
19
22
}
23
+
24
+ @Test
25
+ fun `test serialization deserialization` () {
26
+ val uuid = UUID .fromString(" 00000000-0000-0000-0000-000000000000" )
27
+ val id = RawId (" user" , uuid)
28
+ ByteArrayOutputStream ().use { outputStream ->
29
+ ObjectOutputStream (outputStream).writeObject(id)
30
+ ObjectInputStream (outputStream.toByteArray().inputStream()).use {
31
+ val deserializedId = it.readObject() as RawId
32
+ assertThat(deserializedId).isEqualTo(id)
33
+ }
34
+ }
35
+ }
20
36
}
You can’t perform that action at this time.
0 commit comments