Skip to content

Commit e1728ae

Browse files
committed
default to str instant
1 parent 74f9963 commit e1728ae

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/jvmMain/kotlin/spp/protocol/marshall/KSerializers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ import kotlinx.datetime.Instant
3030
object KSerializers {
3131
class KotlinInstantSerializer : JsonSerializer<Instant>() {
3232
override fun serialize(value: Instant, jgen: JsonGenerator, provider: SerializerProvider) =
33-
jgen.writeNumber(value.toEpochMilliseconds())
33+
jgen.writeString(value.toEpochMilliseconds().toString())
3434
}
3535

3636
class KotlinInstantDeserializer : JsonDeserializer<Instant>() {
3737
override fun deserialize(p: JsonParser, p1: DeserializationContext): Instant =
38-
Instant.fromEpochMilliseconds((p.codec.readTree(p) as JsonNode).longValue())
38+
Instant.fromEpochMilliseconds((p.codec.readTree(p) as JsonNode).asText().toLong())
3939
}
4040
}

src/jvmMain/kotlin/spp/protocol/marshall/ProtocolMarshaller.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ object ProtocolMarshaller {
246246
return LiveInstrumentRemoved(
247247
deserializeLiveInstrument(value.getJsonObject("liveInstrument")),
248248
value.let {
249-
if (it.getValue("occurredAt") is Number) {
249+
if (it.getValue("occurredAt") is String) {
250+
Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong())
251+
} else if (it.getValue("occurredAt") is Number) {
250252
Instant.fromEpochMilliseconds(value.getLong("occurredAt"))
251253
} else {
252254
Instant.fromEpochSeconds(
@@ -300,7 +302,9 @@ object ProtocolMarshaller {
300302
value.getString("breakpointId"),
301303
value.getString("traceId"),
302304
value.let {
303-
if (it.getValue("occurredAt") is Number) {
305+
if (it.getValue("occurredAt") is String) {
306+
Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong())
307+
} else if (it.getValue("occurredAt") is Number) {
304308
Instant.fromEpochMilliseconds(value.getLong("occurredAt"))
305309
} else {
306310
Instant.fromEpochSeconds(
@@ -326,7 +330,9 @@ object ProtocolMarshaller {
326330
value.getJsonObject("artifactQualifiedName")?.let { deserializeArtifactQualifiedName(it) },
327331
LogOrderType.valueOf(value.getString("orderType")),
328332
value.let {
329-
if (it.getValue("timestamp") is Number) {
333+
if (it.getValue("timestamp") is String) {
334+
Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong())
335+
} else if (it.getValue("timestamp") is Number) {
330336
Instant.fromEpochMilliseconds(value.getLong("timestamp"))
331337
} else {
332338
Instant.fromEpochSeconds(
@@ -356,7 +362,9 @@ object ProtocolMarshaller {
356362
return LiveLogHit(
357363
value.getString("logId"),
358364
value.let {
359-
if (it.getValue("occurredAt") is Number) {
365+
if (it.getValue("occurredAt") is String) {
366+
Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong())
367+
} else if (it.getValue("occurredAt") is Number) {
360368
Instant.fromEpochMilliseconds(value.getLong("occurredAt"))
361369
} else {
362370
Instant.fromEpochSeconds(
@@ -380,7 +388,9 @@ object ProtocolMarshaller {
380388
fun deserializeLog(value: JsonObject): Log {
381389
return Log(
382390
value.let {
383-
if (it.getValue("timestamp") is Number) {
391+
if (it.getValue("timestamp") is String) {
392+
Instant.fromEpochMilliseconds(value.getString("occurredAt").toLong())
393+
} else if (it.getValue("timestamp") is Number) {
384394
Instant.fromEpochMilliseconds(value.getLong("timestamp"))
385395
} else {
386396
Instant.fromEpochSeconds(

0 commit comments

Comments
 (0)