Hi,

Yes, why do we need a STATIC serializer ?
A static method makes sense for a deserializer since we don't have an instance at hand.
But I don't understand this restriction for a serializer, because in that case we do have an instance ready.

This gets more frustrating when dealing with enums of Java 5.
Suppose we have an enum called Weekday.
  • A natural deserializer is the pre-defined Weekday.valueOf(String), and it works OK. valueOf is pre-defined for every enum class.
  • A natural serializer would be Weekday.toString(), which is NOT accepted by the binder since it is not static. Why ???
The workaround is to explicitly define a static method as follows :
private static String serializer (Weekday day) { return day.toString(); }
A bit awkward ...

Who could explain this ?
Bye
/Hervé

Reply via email to