0

I'm using Spring Web MVC with FasterXML.

I have a bean with enum field and I'd like this field to be serialized like this:

{
  id: 0,
  name: "VALUE0",
  title: "First Value"
}

I've created an interface TitledEnum with getTitle() method, so my enum field implements this interface. So I have all the required data: id & name from Enum, and title from TitledEnum.getTitle();

So the question is: how to configure serialize / deserialize?

==== UPDATE: Samples:

public enum MyEnum implements TitledEnum {
  VALUE0 ("My First Value");
  //implementation here
}

public class MyBean {
  //@JsonSerialize or @JsonDeserialize here if needed
  private MyEnum enumField;
}

===== Update. I'm looking for a general solution, one serializer for all enums

Mikhail Kopylov
  • 2,008
  • 5
  • 27
  • 58

0 Answers0