Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4176

Struts2 JSON Plugin: Send Map with Strings as Key to JSON Action is ignored, Numeric Keys will work and mapped


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s:
    • Fix Version/s: 2.3.34, 2.5.13
    • Component/s: Plugin - JSON
    • Labels:
    • Environment:

      Tomcat6, Struts,JSON Plugin,jquery


      Sending Map from javascript/jsp to JSON Action, when the Keys are numeric everything works, when the keys are Strings then these entries are thrown away while the mapping process in the JSON Action takes place.
      Important note: If i create a map in the JSON Action and send it to the client everything is ok.

      alert which shows the Server generated JSON:


      If i look into the sended data from javascript side in Eclipse i see in debug mode:

      this=>myJSONMap:{2=[Ljava.lang.String;@3caf7a1f, 23=[Ljava.lang.String;@247aa859}

      Alert shows on client side:


      Hope it's clear where the problem is. Bug or misunderstood anything?
      Would like to have a List of keys,values where the keys can be String/Long/Int and the values can be String/Long/int.

      The direction Server generated Map=>JSON is ok, sending the same from client side will lose the entries with a String key.

      Further i tried also to specify my Map like

      private Map<String, String> propertyValueMap = new LinkedHashMap<String, String>(); 

      and set the getters/setters but don't work either.

      Here is a part of my code:
      JSP PAGE:

      <form action="" id="testForm1">
      testForm1<input type="submit"/>
      event.preventDefault(); //Cancel the default action (navigation) of the click.
      var data={"1":"1","2":"ANOTHERVALUE","ANOTHERKEY":"1","KEY":"VALUE"};
      var sentData={};
      $.getJSON("<s:url namespace="/ajax" action="testMap"/>", sentData ,function(data3) {
      alert("Server generated JSON"+JSON.stringify(data3.mymap));
      alert("Client generated JSON"+JSON.stringify(data3.myJSONMap));

      JSON Action config:

      <package name="PIM_JSONDataPackage" namespace="/ajax" extends="struts-default,json-default">
      <action name="testMap" method="testMap" class="eu.mtd.actions.JSON_DropDownPropertyValuesAction">
      <result type="json" />
      <param name="noCache">true</param>

      JSON Action

      public class JSON_DropDownPropertyValuesAction extends ActionSupport{
      	private static final long serialVersionUID = 1L;
      	private Map session;
      	private Map mymap = new HashMap();
      	private Map myJSONMap = new HashMap();
      public JSON_DropDownPropertyValuesAction(){}
      	public String testMap(){
      		mymap.put("KEY", "VALUE");
      		mymap.put("1", "1");
      		mymap.put("ANOTHERKEY", "1");
      		mymap.put("2", "ANOTHERVALUE");
      		//Creates JSON: {"1":"1","2":"ANOTHERVALUE","ANOTHERKEY":"1","KEY":"VALUE"}
      		return SUCCESS;
      public String execute() {
              return SUCCESS;
      	public Map getMymap() {
      		return mymap;
      	public void setMymap(Map mymap) {
      		this.mymap = mymap;
      	public Map getMyJSONMap() {
      		return myJSONMap;
      	public void setMyJSONMap(Map myJSONMap) {
      		this.myJSONMap = myJSONMap;
      	public Map getSession() {
      		return session;
      	public void setSession(Map session) {
      		this.session = session;


          Issue Links



              • Assignee:
                lukaszlenart Lukasz Lenart
                sabendroth Stefan Abendroth
              • Votes:
                0 Vote for this issue
                4 Start watching this issue


                • Created: