开发者

jaxb unmarshal returns empty hashmap but sets it as null

I wrote an XMLAdapter for my HashMap. On unmarshaling an empty hashmap (presented by an empty array), I initialize an empty hashmap and return it, as seen in the code.

@开发者_开发问答Override
public Map<ServiceAttributeVO, String> unmarshal(ServiceAttributeVOXMLMap serviceAttributeMap) throws Exception {
    Map<ServiceAttributeVO, String> r = new HashMap<ServiceAttributeVO, String>();

    if (serviceAttributeMap.mapElementList == null) { //if empty list, return the empty hashmap
        return r;
    }
    for (ServiceAttributeVOMapElement mapelement : serviceAttributeMap.mapElementList) {
        r.put(mapelement.key, mapelement.value);
    }
    return r;
}

One would think that the resulted object would contain this empty hashmap, but in reality the hashMap has value null.

What to do?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜