我在案例类Foo中有一个我不想序列化的属性。但是,这是一个复杂的案例类,如果可能的话,我想使用自动Json.writes宏对其进行序列化。是否可以在案例类中注释属性,以确保其未序列化]
case class Foo(
serializeMe: String,
ignoreMe: String
)
val toSerialize = Foo("value1", "Value To Be Ignored")
Json.writes[Foo].writes(toSerialize)
这应该序列化为
{
"serializeMe": "value1"
}
我尝试过:
case class Foo(
serializeMe: String,
@JsonIgnore ignoreMe: String
)
也是
case class Foo(
serializeMe: String,
@JsonProperty(access = Access.WRITE_ONLY) ignoreMe: String
)
这些似乎都没有受到宏的尊重。任何帮助将不胜感激
您可以尝试使用这种方法:Play Framework - how to ignore some fields for Json Serialisation?
但是,需要手动描述所有其他字段的序列化,这会导致一些重复。