1

I'm attempting to use Struts2 JSON plugin to serialize a JSON for a jQuery-ui autocomplete AJAX call. The format is from: jQueryUI Docs

An array of objects with label and value properties:

 [ { label: "Choice1", value: "value1" }, ... ]

I have this POJO:

public class AutoCompleteJqueryBean {

    private Long value;
    private String label;


    public Long getValue() {
        return value;
    }

    public void setValue(Long value) {
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public AutoCompleteJqueryBean(String label, Long value){
        this.label = label;
        this.value = value;
    }
}

Which is serializing to this JSON:

{"sponsors":[{"label":{"label":"A Duplicate"},"value":{"value":410}},{"label":{"label":"A Duplicate 2"},"value":{"value":319}},{"label":{"label":"A Duplicate 3"},"value":{"value":128}},{"label":{"label":"A Duplicate 4"},"value":{"value":191}}]}

I've also tried maps to no avail. How can I force the jQuery Autocomplete format?

The action has an array of AutoCompleteJqueryBean with public getters/setters.

1 Answer 1

2

Struts2 JSON plugin is serializing your entire action.

If sponsors is a List<AutoCompleteJqueryBean> (or some other type of array or collection) and you want to prevent returning it in your result, you need to set it as root object in the configuration:

<result type="json">
    <param name="root">sponsors</param>
</result>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.