I would like to mark the default method generated by scala compiler to be ignored from being serialized.
@JsonIgnore def getSum(a: Int, b: Int = 2): Int = a + b
compiler creates two methods:
def getSum(a: Int, b: Int): Int = a.+(b);
<synthetic> def getSum$default$2(): Int = 2; (default value at position 2)
The first method getSum does not get serialized as the JsonIgnore is applied on it, but the new default parm method generated is serialized by jackson, how to tell Jackson to not serialize it?
Example:
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.ObjectMapper;
case class A(id: Int) {
@JsonIgnore def getSum(a: Int, b: Int = 2): Int = a + b
}
@Test
def test(): Unit = {
val a = A(5)
val mapper = new ObjectMapper()
println(mapper.writeValueAsString(a))
}
output: {"id":5,"sum$default$2":2}