Skip to content

fix #193: Connector deserialization when tariffIds is absent from json#194

Merged
lilgallon merged 1 commit into
mainfrom
fix/#193-kx-tariffids-serialization
Mar 3, 2026
Merged

fix #193: Connector deserialization when tariffIds is absent from json#194
lilgallon merged 1 commit into
mainfrom
fix/#193-kx-tariffids-serialization

Conversation

@lilgallon

Copy link
Copy Markdown
Member

closes #193

Updated SkipNullsListSerializer.deserialize to follow the standard kotlinx.serialization convention for nullable serializers: check decoder.decodeNotNullMark() before reading any token from the stream. When the decoder signals the value is null (either because the field is absent or because the JSON value is null), the method now returns null immediately without touching the stream.

  // Before
  return when (val jsonElement = jsonDecoder.decodeJsonElement()) {
      is JsonNull -> null
      is JsonArray -> { ... }
      else -> throw SerializationException("Expected array or null for List")
  }

  // After
  if (!decoder.decodeNotNullMark()) return decoder.decodeNull()
  return when (val jsonElement = jsonDecoder.decodeJsonElement()) {
      is JsonArray -> { ... }
      else -> throw SerializationException("Expected array for List")
  }

Added two new parameterized test cases in ConnectorMapperTest (run against all available serializers):

  • tariff_ids field entirely absent from JSON → tariffIds decoded as null
  • "tariff_ids": null explicit null in JSON → tariffIds decoded as null

@lilgallon lilgallon added the bug Something isn't working label Mar 2, 2026
@lilgallon
lilgallon force-pushed the fix/#193-kx-tariffids-serialization branch from 2127859 to 8f55914 Compare March 3, 2026 07:22
@sonarqubecloud

sonarqubecloud Bot commented Mar 3, 2026

Copy link
Copy Markdown

@lilgallon
lilgallon merged commit c9ac5b6 into main Mar 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kotlinx.serialization connector deserialization issue when there are no tariffIds

1 participant