Skip to content
Advertisement

How to print enum description

Im creating a Java application, I used enum to create movie category. When I input MovieCategory.WAR I would like to see War movie(My description) instead of WAR. How is it possible? I tried MovieCategory.WAR.getDescription() but does’t work.

JavaScript
JavaScript

Advertisement

Answer

The enum works correctly:

JavaScript

Or, maybe you want the toString method to use description?

JavaScript

UPDATE #3: It seems the issue is the JSON response. If you want the description to be returned, you can annotate the getDescription method wtih @JsonValue.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement