Skip to content

Commit

Permalink
Add encoding value classes
Browse files Browse the repository at this point in the history
  • Loading branch information
BOOMeranGG committed Sep 1, 2023
1 parent 75c562a commit 7eadee5
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public abstract class TomlAbstractEncoder protected constructor(
}
}

@Suppress("NESTED_BLOCK")
override fun <T> encodeSerializableValue(serializer: SerializationStrategy<T>, value: T) {
when (val desc = serializer.descriptor) {
instantDescriptor,
Expand All @@ -133,16 +134,14 @@ public abstract class TomlAbstractEncoder protected constructor(
}
else -> when (val kind = desc.kind) {
is StructureKind,
is PolymorphicKind -> if (desc.isInline) {
serializer.serialize(this, value)
} else if (!encodeAsKey(value as Any, desc.serialName)) {
val encoder = encodeStructure(kind)

serializer.serialize(encoder, value)

elementIndex = encoder.elementIndex

attributes.reset()
is PolymorphicKind -> when {
desc.isInline -> serializer.serialize(this, value)
!encodeAsKey(value as Any, desc.serialName) -> {
val encoder = encodeStructure(kind)
serializer.serialize(encoder, value)
elementIndex = encoder.elementIndex
attributes.reset()
}
}
else -> super.encodeSerializableValue(serializer, value)
}
Expand Down Expand Up @@ -216,9 +215,7 @@ public abstract class TomlAbstractEncoder protected constructor(
StructureKind.CLASS -> {
// We should keep previous key when we have value (inline) class
// But if key is null, it means that value class isn't nested, and we have to use its own key
if (descriptor.isInline && attributes.key != null) {
// do nothing
} else {
if (!descriptor.isInline || attributes.key == null) {
setKey(descriptor.getElementName(index))
}
}
Expand Down

0 comments on commit 7eadee5

Please sign in to comment.