while (iter.hasNext()) { Map.Entry entry = (Map.Entry)iter.next(); ctx.startTagAttributes(m_index, getEntryElementName()); ctx.attribute(m_index, getKeyAttributeName(), entry.getKey().toString()); if (entry.getValue() instanceof IMarshallable) { ((IMarshallable)entry.getValue()).marshal(ctx); ctx.endTag(m_index, getEntryElementName()); } else { throw new JiBXException("Mapped value is not marshallable");
public Object unmarshal(Object obj, IUnmarshallingContext ictx) throws JiBXException { // make sure we're at the appropriate start tag UnmarshallingContext ctx = (UnmarshallingContext)ictx; if (!ctx.isAt(m_uri, m_name)) { ctx.throwStartTagNameError(m_uri, m_name); } // create new hashmap if needed int size = ctx.attributeInt(m_uri, getSizeAttributeName(), DEFAULT_SIZE); Map map = (Map)obj; if (map == null) { map = new HashMap(size); } // process all entries present in document ctx.parsePastStartTag(m_uri, m_name); while (ctx.isAt(m_uri, getEntryElementName())) { Object key = ctx.attributeText(m_uri, getKeyAttributeName(), null); ctx.parsePastStartTag(m_uri, getEntryElementName()); Object value = ctx.unmarshalElement(); map.put(key, value); ctx.parsePastEndTag(m_uri, getEntryElementName()); } ctx.parsePastEndTag(m_uri, m_name); return map; } }