Skip to content

FEATURE: Deserialization support for default values#391

Merged
kishorereddy merged 6 commits into
mainfrom
fix/2501230-model-deserialize
Jan 31, 2026
Merged

FEATURE: Deserialization support for default values#391
kishorereddy merged 6 commits into
mainfrom
fix/2501230-model-deserialize

Conversation

@kishorereddy

@kishorereddy kishorereddy commented Jan 30, 2026

Copy link
Copy Markdown
Collaborator

Overview

This library kiit.serialization will likely be replaced with kotlinx.serialization.
For now, this feature added until further research/effort is put into kotlinx.serialization for the use cases here and in the client apps of kiit.

// Sample Type with null and default values.
data class SampleObject2(
   val tStr1:String, 
   val tStr2:String? = null, 
   val tDate: DateTime = DateTimes.now(), 
   val tBool:Boolean = true, 
   val tInt:Int = 0
)

fun test_object_with_nulls_defaults(sample2: SampleObject2):Unit{
    // work here.
}

// Test deserializing with nulls and default values ( from instance ) - see below 
val tests = listOf<String>(
    """{ "sample2": { "tStr1": "abc" } }""",
    """{ "sample2": { "tStr1": "abc", "tStr2": "123" } }""",
    """{ "sample2": { "tStr1": "abc", "tStr2": "123", "tDate": "2026-01-30T18:00:00Z" } }""",
    """{ "sample2": { "tStr1": "abc", "tStr2": "123", "tDate": "2026-01-30T18:00:00Z", "tBool": false } }""",
    """{ "sample2": { "tStr1": "abc", "tStr2": "123", "tDate": "2026-01-30T18:00:00Z", "tBool": false, "tInt": 2 } }""",
)
val date = DateTimes.parse("2026-01-30T18:00:00Z")
val expectedItems = listOf(
    SampleObject2("abc"),
    SampleObject2("abc", "123"),
    SampleObject2("abc", "123", date),
    SampleObject2("abc", "123", date, false),
    SampleObject2("abc", "123", date, false, 2),
)

// Use the default objects for getting properties for nulls/default values
val deserializer = JsonDeserializer(
    defaults = mapOf(
           SampleObject2::class.qualifiedName!! to SampleObject2("test")
     )
)
val results = deserializer.deserialize(this::test_object_with_nulls_defaults.parameters, tests[0])
            

Ticket(s)

n/a

Links(s)

n/a

Dependencies

n/a

Design

WIP

Notes

n/a

Pending

n/a

Tests

  1. Cleaned up the Deserialization tests
  2. Added tests for loading nulls and default values

@kishorereddy kishorereddy changed the title FEATURE: Deserialization with support for default values FEATURE: Deserialization support for default values Jan 31, 2026
@kishorereddy kishorereddy merged commit 0626621 into main Jan 31, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant