Skip to content

Feature: Default Parameters#5

Open
n0900 wants to merge 5 commits into
feature/betterTypesfrom
feature/default_paramters
Open

Feature: Default Parameters#5
n0900 wants to merge 5 commits into
feature/betterTypesfrom
feature/default_paramters

Conversation

@n0900

@n0900 n0900 commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Adds default parameters to backedProperty so that JsonConfiguration.encodeDefaults is honored

for slices this is not applicable because default behavior is different:

  • when used on an existing JsonBackedObject it returns a read-only view where it tries to deserialize from the underlying raw JsonObject according to the serializer used to define the instance.
  • when constructing the object encodeDefaults of the serializer used to cast any object to JsonObject decides whether it encodes default values or not. It would be wise to hand over this serializer in the constructor but this is not enforcable.

@n0900 n0900 requested a review from JesusMcCloud June 17, 2026 16:01
@n0900 n0900 self-assigned this Jun 17, 2026

@JesusMcCloud JesusMcCloud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am almost certain, the tests do not cover all combinations of default values, nullable values ancodeNulls=true/false


private fun registerDefault(thisRef: O, property: KProperty<*>) {
if (!hasDefault) return
val defaults = thisRef as? ObjectBackedDefaults<*, *> ?: return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can this not be prevented in other ways?

}
return thisRef.codec.nullElement()
}
return thisRef.codec.encode(serializer, value)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is one an accessor and the other an encode call?

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.

2 participants