Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Annotation to ignore a property if that property is null #190

Closed
electricjones opened this issue Aug 6, 2018 · 1 comment
Closed

Comments

@electricjones
Copy link

I have run into a situation where I need to serialize a data class, but one of the properties is nullable, and I need to NOT include that property if the value is null.

@Serializable
data class Operation(
        val op: OperationType, // enumeration
        val pathString: String,
        @Optional val value: String? = null
) {}

When serialized, this gives a json object with three properties.

Ideally, there would be an annotation similar to @Transient like @TransientIfNull.

If there is a way to do this with a CustomSerializer, that would be great, too. Thank you.

@electricjones
Copy link
Author

Nevermind, I just saw #58. I am going to close this, vote for that, and connect the two.

Thank you.

sandwwraith added a commit that referenced this issue Dec 12, 2018
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

No branches or pull requests

1 participant