Skip to content

Spring Castor Unmarshaller [SPR-10477] #15110

@spring-projects-issues

Description

@spring-projects-issues

AX opened SPR-10477 and commented

Hi,

i cannot ignore extra elements using spring oxm and castor. There is always an error at the log file:

org.springframework.oxm.UnmarshallingFailureException: Castor unmarshalling exception; nested exception is org.exolab.castor.xml.MarshalException: Unable to find FieldDescriptor for 

I'm using the following xml configuration:

<bean id="XmlConverter" class="de.ax.castor.XmlConverter">
		<property name="marshaller" ref="castorMarshaller" />
		<property name="unmarshaller" ref="castorMarshaller" />
	</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller">
		<property name="ignoreExtraElements" value="true"/>
		<property name="ignoreExtraAttributes" value="true"/>
		
	</bean>
public class XmlConverter {
    
    protected final Log log = LogFactory.getLog(getClass());

    private Marshaller marshaller;
    private Unmarshaller unmarshaller;
 
    public Marshaller getMarshaller() {
        return marshaller;
    }
 
    public void setMarshaller(Marshaller marshaller) {
        this.marshaller = marshaller;
    }
 
    public Unmarshaller getUnmarshaller() {
        return unmarshaller;
    }
 
    public void setUnmarshaller(Unmarshaller unmarshaller) {
        this.unmarshaller = unmarshaller;
    }
 
    public void convertFromObjectToXML(Object object, String filepath)
        throws IOException {
 
        FileOutputStream os = null;
        try {
            os = new FileOutputStream(filepath);
            getMarshaller().marshal(object, new StreamResult(os));
        } finally {
            if (os != null) {
                os.close();
            }
        }
    }
 
    public Object convertFromXMLToObject(String xmlfile) throws IOException {
 
        FileInputStream is = null;
        try {
            is = new FileInputStream(xmlfile);
            return getUnmarshaller().unmarshal(new StreamSource(is));
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }
    
    public Object convertFromByteArrayOutputStreamtoObject(ByteArrayOutputStream baos) throws XmlMappingException, IOException {
        try {
            InputStream is = new ByteArrayInputStream(baos.toByteArray());
            return getUnmarshaller().unmarshal(new StreamSource(is));
        } finally {
        }
    }
    
    public Object convertFromStringtoObject(String string) throws XmlMappingException, IOException {
        try {
//            CastorMarshaller unm = (CastorMarshaller) getUnmarshaller();
//            unm.setIgnoreExtraElements(true);
//            unm.setIgnoreExtraAttributes(true);
            return getUnmarshaller().unmarshal(new StreamSource(IOUtils.toInputStream(string)));
        } 
        finally {
        }
    }
}

But it seems that this has no effects to castor.

Please give me some information how to solve this.

Best regards

Alex


Affects: 3.1.1

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions