Skip to content

Set explicitNulls = false for kotlinx serialization#2897

Open
Luna712 wants to merge 1 commit into
recloudstream:masterfrom
Luna712:patch-1
Open

Set explicitNulls = false for kotlinx serialization#2897
Luna712 wants to merge 1 commit into
recloudstream:masterfrom
Luna712:patch-1

Conversation

@Luna712
Copy link
Copy Markdown
Contributor

@Luna712 Luna712 commented Jun 6, 2026

This is more inline with Jackson's behavior otherwise for nullable types with non default values, and they don't exist, gives a Missingfield exception whereas it worked on Jackson. We may need coerceInputValues = true also but I am unsure of that right now.

This is more inline with Jackson's behavior otherwise for nullable types with non default values, and they don't exist, gives a Missingfield exception whereas it worked on Jackson. We may need coerceInputValues = true also but I am unsure of that right now.
@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

Actually this also prevents the encoding of explicit null values as well so it is a little different but it is the closest I could fine. I am actually unsure of this...

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

Actually docs are just confusing...
https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-builder/explicit-nulls.html

says null values are omitted but the example shows it encoding null values if they are explicit. yeah I am just getting confused the example uses two separate Json instances. Perhaps we just want to force default values for nullable fields, unsure. Even then it would be a bit different behavior than Jackson.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

@fire-light42 any thoughts here? (to note I was testing with a fully migrated everything and removed Jackson fallback to uncover a few issues with our current Json setup)

@fire-light42
Copy link
Copy Markdown
Collaborator

We do aim to simulate exact Jackson behavior however possible, if this helps with that I see no issues. However, I would see these edge cases before I can make a proper decision.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

For example in RepositoryManager SitePlugin no plugins can load on kotlinx serialization if things like description is not passed. I got Missingfield exception on description in that case.

@fire-light42
Copy link
Copy Markdown
Collaborator

In that case we absolutely need explicitNulls = false, but coerceInputValues is not what we want. Turning nulls to default values is very unexpected behavior.

@fire-light42
Copy link
Copy Markdown
Collaborator

I dislike that encoding also strips the null. It should always encode null values, but allow missing null values too.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

As far as I can tell, it can't do both.

As for coerceInputValues from my understanding, that turns invalid values to default values in some cases like nulls on non nullable types or an invalid enum.

@fire-light42
Copy link
Copy Markdown
Collaborator

Unfortunate, but the explicitNulls behavior will still work with Jackson because missing fields become null. It just prevents us from turning it on in the future.

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

Okay this should not be done. It corrupts all data. I just did some more tests and restoring from previous backups causes a lot of data to be corrupted or just plain missing

@Luna712
Copy link
Copy Markdown
Contributor Author

Luna712 commented Jun 6, 2026

Nevermind, that was my fault. Ironically the cause that broke it was that this fixed it in way more places then I thought, it was catching back to Jackson but this made it actually work to use kotlinx serialization but I had it wrong in my full migration, after fixing that if fully works. So this is still needed.

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