pushka
pushka copied to clipboard
How to ignore some fields from serialization?
lets look what i mean
@pushka
case class BaseMessage(uid: String)
@pushka
case class HandshakeRequest(@pushkaIgnore uid: String, user: String, timestamp: String, token: String) extends BaseMessage(uid)
i want to ignore from serialization uid at HandshakeRequest
How to do that?
Hi!
In a difference with Jackson which designed to operate mutable objects, pushka designed to work with immutable case classes. Also null is disallowed. So we can't just ignore a fields. If field will be not written, how it can be read without nullability? Right answer is Option. If the field can be ignored it is an optional field.
@pushka
sealed abstract class BaseMessage(uid: Option[String])
object BaseMessage {
case class HandshakeRequest(user: String, timestamp: String, token: String, uid: Option[String] = None) extends BaseMessage(uid)
}
uid should be defined but not serialized, in that case Option[...] is not a way