Struts2 with holiday plugin: JSON map value for ENUM

I am using Struts2 with a plugin to create RESTful web services. Serialization from Java objects to JSON was a breeze - everything was correctly and beautifully displayed. Getting JSON and trying to map it to Java objects is a completely different issue.

I ran into two problems:

1) Failed to convert the JSON array to List. Solved by String [].

2) There ENUM - JSON, for example:

{"feature":{"id":2,"enabled":true,"description":"one click transactions feature","type":"ONECLICK_OPTIN_TRANSACTIONS"},"countries":["SG"],"clientId":10} 

"type": "ONECLICK_OPTIN_TRANSACTIONS" should be displayed in ENUM in the Java object, but, of course, Struts2 barfs.

Has anyone successfully done this?

For reference, this is the corresponding part of the exception:

 Method public java.lang.String org.apache.commons.lang.exception.NestableRuntimeException.getMessage(int) threw an exception when invoked on net.sf.ezmorph.MorphException: com.foo.bar.entity.FeatureType 

Thanks Shaun

+4
source share
1 answer

No, there is no such thing as Enums in JSON. Of course, there is work to do this, for example, using a hash table, but it's always good to think in accordance with technology.

0
source

Source: https://habr.com/ru/post/1439296/


All Articles