Skip to content

Feature flag to serialize unitialized lateinit properties into null #882

Description

@SButterfly

Use case

We log entity classes before saving them to the database

data class MyEntity(
 val text: String,
... other required properties
) {
lateinit var createAt: Instant // this field is initialized after the entity is saved to the Database
}

fun save(entity: MyEntity) {
  log.info("About to save ${objectMapper.writeValueAsString(entity)}")
  repository.save(entity)
}

Describe the solution you'd like

A new feature flag

    val module = KotlinModule.Builder()
            .configure(KotlinFeature.UnintializedLateInitToNull, true) // to write them as nulls
            .configure(KotlinFeature.UnintializedLateInitToIgnore, true) // or to avoid them
          .build()

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions