Skip to content

Add option to use default case class value during decoding of AvroTransient field#904

Merged
sksamuel merged 2 commits into
sksamuel:masterfrom
minosiants:dafault-value
Apr 6, 2026
Merged

Add option to use default case class value during decoding of AvroTransient field#904
sksamuel merged 2 commits into
sksamuel:masterfrom
minosiants:dafault-value

Conversation

@minosiants

Copy link
Copy Markdown
Contributor

Hello,
My use case is read data in protobuf format and translate it into avro format.
For protobuf I use scalapb library and it generates model case classes based on protobuf schema.
Generated case classes have UnknownFieldSet filed with default empty value. (There is an option to exclude them but I need them for analysis).
scalapb allows to inject annatations into generated classes (https://scalapb.github.io/docs/customizations#adding-annotations) so to exclude UnknownFieldSet filed from avro schema I use AvroTransient annotation. Everything works fine one model fror protobuf and avro but when avro4s tries to decode value that is marked with AvroTransient it returns None which cause class cast exception.

I added useDefault boolean flag into AvroTransient so now if it is true defalut value from the case class is used istead on none

@sksamuel

sksamuel commented Apr 6, 2026

Copy link
Copy Markdown
Owner

FYI failing tests

@minosiants

Copy link
Copy Markdown
Contributor Author

It fails on import pgp key. Not sure if it is part of the test. I will have a look

@sksamuel

sksamuel commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Might just need keys updated for latest central ?

@minosiants minosiants closed this Apr 6, 2026
@minosiants minosiants reopened this Apr 6, 2026
@minosiants

Copy link
Copy Markdown
Contributor Author

Sam I've added pgp key to the project setting I think it was the reason why it failed . Could you please try it again

@sksamuel

sksamuel commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Ran again

@minosiants

Copy link
Copy Markdown
Contributor Author

Sam I added condition to run gpg steps only if PR is not from fork .
Github does not pass secrets from forks repos

https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets#using-secrets-in-a-workflow

@minosiants

Copy link
Copy Markdown
Contributor Author

@sksamuel it is green now :)

@sksamuel sksamuel merged commit fc247a3 into sksamuel:master Apr 6, 2026
1 check passed
@sksamuel

sksamuel commented Apr 6, 2026

Copy link
Copy Markdown
Owner

Merged!

@minosiants minosiants deleted the dafault-value branch April 7, 2026 00:26
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