XMLまたはJSONを使用してGETメソッドでHashMap>型のオブジェクトを返したい。クライアント側では、マップのキーを取得しますが、値は null です。
これはリターンクラスです:
private HashMap<String, ArrayList<String>> hashMap = new HashMap<>();
public HashMap<String, ArrayList<String>> getHashMap() {
return hashMap;
}
public void setHashMap(HashMap<String, ArrayList<String>> hashMap) {
this.hashMap = hashMap;
}
これはサービス内の GET メソッドです。
@GET
@Path("/mapa")
@Produces(MediaType.APPLICATION_XML)
public Test mapa() {
Test test = new Test();
HashMap<String, ArrayList<String>> hashMap = new HashMap<>();
ArrayList<String> list = new ArrayList<>();
list.add("first");
list.add("second");
hashMap.put("first", list);
test.setHashMap(hashMap);
return test;
}
私はブラウザでこれを取得します:
<test>
<hashMap>
<entry>
<key>first</key>
<value/>
</entry>
</hashMap>
</test>
値が空なのはなぜですか?