I have a scala case class:
case class Person(name: String, age: Int) {
def isMillenial: Boolean = age <= someConstantMillenialThreshold
}
This serializes into the following json (using the ScalaJsonFactory object mapper to serialize):
{
name: "foo",
age: 42
}
However I want it to be serialized as follows:
{
name: "foo",
age: 42,
isMillenial: true
}
Is there any way of doing this in a simple way, preferably by using some Jackson annotation or something similar? Basically looking for any solution which doesn't involve changing the case class Person
or creating new objects