سؤال

I'm currently working on making an Struts 2 Action call with a JSON response - I'd like to have the response be cache-able, which means I need to get the JSON generated within the code before the call is made. Something like this, within and action's execute() method:

String json = this.getJSONOutput();
JSONCacheUtils.cache(hash, json);

Is there any way to do this using the Struts 2 JSON library?

هل كانت مفيدة؟

المحلول

You can use Struts2 JSON plugin API to serialize object. The same way JSONResult is doing when it's executed.

String json = JSONUtil.serialize(rootObject, excludeProperties, includeProperties, ignoreHierarchy, enumAsBean, excludeNullProperties);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top