Index: org/exolab/castor/xml/Marshaller.java =================================================================== --- org/exolab/castor/xml/Marshaller.java (Revision 7205) +++ org/exolab/castor/xml/Marshaller.java (Arbeitskopie) @@ -1373,6 +1373,8 @@ String path = attDesc.getLocationPath(); if (name.equals(path)) { mstate.nestedAtts[i] = null; + // TODO: Should this not be '--mstate.nestedAttcount'? Setting to zero + // sometimes prevents the subsequent attribute values to be processed mstate.nestedAttCount = 0; processAttribute(mstate.getOwner(), attDesc, atts); } @@ -1763,7 +1765,27 @@ } } - if (obj == null || (obj instanceof Enumeration && !((Enumeration)obj).hasMoreElements())) { + + // TODO: If element 'text' value is null and is not required then it skips attribute + // processing. I think there should be a check that if the element has attributes with + // non-null values then the attributes should be processed here instead of processing them + // later + + // TODO: add a check that checks with nestedAtts, whether any Attributes held there + // has/includes a path/location that equals the current element name (xml) + + boolean hasNestedAttributes = false; + if (nestedAtts.length > 0) { + for (int j = 0; j < nestedAtts.length; j++) { + XMLFieldDescriptor attributeDescriptor = nestedAtts[j]; + String locationPath = attributeDescriptor.getLocationPath(); + if (locationPath.equals(elemDescriptor.getXMLName())) { + hasNestedAttributes = true; + break; + } + } + } + if ((obj == null && !hasNestedAttributes) || (obj instanceof Enumeration && !((Enumeration)obj).hasMoreElements())) { if (elemDescriptor.isNillable() && (elemDescriptor.isRequired())) { nil = true; } @@ -1858,7 +1880,10 @@ obj = new NilObject(classDesc, elemDescriptor); } - final Class type = obj.getClass(); + Class type = null; + if (obj != null) { + type = obj.getClass(); + } MarshalState myState = mstate.createMarshalState(object, name); myState.nestedAtts = nestedAtts; @@ -1866,11 +1891,11 @@ //-- handle byte arrays - if (type.isArray() && (type.getComponentType() == Byte.TYPE)) { + if (type != null && type.isArray() && (type.getComponentType() == Byte.TYPE)) { marshal(obj, elemDescriptor, handler, myState); } //-- handle all other collection types - else if (isCollection(type)) { + else if (type != null && isCollection(type)) { boolean processCollection = true; if (_saveMapKeys) { MapHandler mapHandler = MapHandlers.getHandler(type); @@ -1921,6 +1946,9 @@ } + // TODO: Handling additional attributes at the end causes elements to be marshalled in the wrong + // order when element 'text' is null, but their attribute value is not null. Can this be fixed + // to process element attributes even when the element text value is null? //-- Handle any additional attribute locations that were //-- not handled when dealing with wrapper elements