jersey - De/serializing an enumerator type with Jackson -


i have entity serializing json , deserailizing json:

public class item {     @jsonproperty private status status;  ....  } 

the status enumeration looks like:

public enum status {      new,     active,     pending,     error; } 

i want annotated enumeration type serialize to, example, {status: "new"} , same deserialize enumeration type. there separate annotation this?

you need additional methods in enum:

@override @jsonvalue public string tostring() {     return super.tostring().touppercase(locale.english); }  @jsoncreator public static status fromstring(final string status) {   if (status == null)   {     return null;   }   try   {     return valueof(status.touppercase(locale.english));   }   catch (illegalargumentexception iae)   {     system.err.println("invalid status");   } } 

these ensure status conversion case-insensitive (so status of 'new' still convert correct enum).


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -