开发者

jaxb unmarshal returns empty hashmap but sets it as null

开发者 https://www.devze.com 2023-03-28 11:30 出处:网络
I wrote an XMLAdapter for my HashMap. On unmarshaling an empty hashmap (presented by an emptyarray), I initialize an empty hashmap and return it, as seen in the code.

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

精彩评论

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

关注公众号