struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Artashes Hovasapyan <>
Subject Struts 2 JSON plugin
Date Mon, 18 Jan 2010 23:01:30 GMT

I've just started using JSON plugin and noticed strange behaviour. It looks
like JSON annotation fields are completely ignored by the plugin. My action
looks like this:

public class TestAction extends ActionSupport {
    private Date date;

    @JSON(format = "yyyy-MM-dd HH:mm:ss Z")
    public Date getDate() {
        return date;

    public void setDate(Date date) { = date;

    public String test() {
        date = new Date();
        return "success";

Struts configuration looks like this:

    <package name="test" extends="json-default">
        <action name="Test" class="org.test.TestAction" method="test">
            <result name="success" type="json">
                <param name="root">date</param>

Result date is serialized according to default "yyyy-MM-dd'T'HH:mm:ss"

Further research showed that JSONResult.execute() method calls
JSONUtil.serialize() (line 198), which in turn calls
JSONWriter.write()(line 112). This
JSONWriter.write() method calls JSONWriter.value() method (line 99), which
has 2 parameters - actual object to be serialized and the method, which
supposed to be the getter method of the serializable object (at least that's
how it looks to me). Apparently  JSONWriter.write() calls
JSONWriter.value()only passing the object,
null is passed instead of the method. That's where I got confused the most -
if the method is not propagated, how the plugin will pick the annotation
Any idea anyone? Maybe developers can help me with this?

Artashes Hovasapyan

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message