Веб-сервис Hash Map JaVa избавляется от <item></item> - PullRequest
0 голосов
/ 21 января 2019

Я пытаюсь изменить имя тега на команду, и теперь мой веб-сервис генерирует этот ответ:

    <?xml version="1.0" encoding="UTF-8"?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <S:Body>
        <ns2:MapTestResponse xmlns:ns2="http://infomracje/">
            <return>
                <Teams>
                    <item>
                        <Kryptonim>Ratownik 117</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 19</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 154</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 18</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 15</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 17</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 156</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 16</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 111</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 22</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 21</Kryptonim>
                        <Status>lot</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 24</Kryptonim>
                        <Status>lot</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 23</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 20</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>EMS MXH</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>EMS MXI</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 206</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 106</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 406</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 306</Kryptonim>
                        <Status>kon</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 11</Kryptonim>
                        <Status>lot</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 10</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 13</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 12</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 1</Kryptonim>
                        <Status>lot</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 2</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 3</Kryptonim>
                        <Status>tra</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 4</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 5</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 6</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 7</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 8</Kryptonim>
                        <Status>got</Status>
                    </item>
                    <item>
                        <Kryptonim>Ratownik 9</Kryptonim>
                        <Status>got</Status>
                    </item>
                </Teams>
            </return>
        </ns2:MapTestResponse>
    </S:Body>
</S:Envelope>

И вот код, который я использую для создания элементов карты:

public class MapElements {
        @XmlElement public String  Kryptonim;
      @XmlElement public String Status;

      private MapElements() {} //Required by JAXB

      public MapElements(String Kryptonim, String Status)
      {
        this.Kryptonim   = Kryptonim;
        this.Status = Status;
      }

    }

А вот класс MapAdpter:

class MapAdapter extends XmlAdapter<MapElements[], Map<String, String>> {
    public MapElements[] marshal(Map<String, String> arg0) throws Exception {
        MapElements[] mapElements = new MapElements[arg0.size()];
        int i = 0;
        for (Map.Entry<String, String> entry : arg0.entrySet())
            mapElements[i++] = new MapElements(entry.getKey(), entry.getValue());

        return mapElements;
    }
public Map<String, String> unmarshal(MapElements[] arg0) throws Exception {
    Map<String, String> r = new HashMap<String, String>();
    for (MapElements mapelement : arg0)
        r.put(mapelement.Kryptonim, mapelement.Status);
    return r;
}



}

Последним здесь является корневой класс, в который я могу поместить информацию из базы данных в

    @XmlRootElement
public class Root
{

  @XmlJavaTypeAdapter(MapAdapter.class)
  private Map<String, String> Teams;

  public Root()
  {
    Teams = new HashMap<String, String>();

  }
    public void TeamAdd(String kryptonim,String status)   { Teams.put(kryptonim, status); }

    }

Итак, мой вопрос, как переименовать этот тег <item>? Я довольно новичок в программировании Java на веб-сервисах.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...