1

I have a property in a case class Foo which I don't want to serialize. However, it's a complicated case class and if possible I'd like to use the automatic Json.writes macro to serialize it. Is it possible to annotate a property in the case class to ensure it is not serialized

case class Foo(
  serializeMe: String,
  ignoreMe: String
)


val toSerialize = Foo("value1", "Value To Be Ignored")
Json.writes[Foo].writes(toSerialize)

This should serialize to

{
  "serializeMe": "value1"
}

I tried:

case class Foo(
  serializeMe: String,
  @JsonIgnore ignoreMe: String
)

and also

case class Foo(
  serializeMe: String,
  @JsonProperty(access = Access.WRITE_ONLY) ignoreMe: String
)

None of these seem to be respected by the macro. Any help would be much appreciated

Rahil Shah
  • 183
  • 1
  • 4

1 Answers1

0

You can try using this approach: Play Framework - how to ignore some fields for Json Serialisation?

However, it would require to manually describe serialization of all other fields, which leads to some boilerplate..

Rayan Ral
  • 1,862
  • 2
  • 17
  • 17