Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Castor mappings are added multiple times [SWS-418] #567

Closed
gregturn opened this issue Aug 20, 2008 · 2 comments
Closed

Castor mappings are added multiple times [SWS-418] #567

gregturn opened this issue Aug 20, 2008 · 2 comments
Assignees
Milestone

Comments

@gregturn
Copy link
Member

@gregturn gregturn commented Aug 20, 2008

Andreas Stubenrauch opened SWS-418 and commented

When using multiple mapping files for castor the CastorMarshaller adds each mapping several times.

i.e.
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" >
<property name="mappingLocations">
<list>
<value>classpath:file1.xml</value>
<value>classpath:file2.xml</value>
<value>classpath:file3.xml</value>
</list>
</property>
</bean>

The mappings from file1 are added 3 times because the addMapping() method is called within the loop with the entire mapping.
I think method

protected XMLContext createXMLContext(Resource[] mappingLocations, Class targetClass)
        throws MappingException, IOException, ResolverException {
    XMLContext context = new XMLContext();
    if (!ObjectUtils.isEmpty(mappingLocations)) {
        Mapping mapping = new Mapping();
        for (int i = 0; i < mappingLocations.length; i++) {
            mapping.loadMapping(SaxUtils.createInputSource(mappingLocations[i]));
            context.addMapping(mapping);
        }
    }
    if (targetClass != null) {
        context.addClass(targetClass);
    }
    return context;
}

Should actually look like this

protected XMLContext createXMLContext(Resource[] mappingLocations, Class targetClass)
        throws MappingException, IOException, ResolverException {
    XMLContext context = new XMLContext();
    if (!ObjectUtils.isEmpty(mappingLocations)) {
        Mapping mapping = new Mapping();
        for (int i = 0; i < mappingLocations.length; i++) {
            mapping.loadMapping(SaxUtils.createInputSource(mappingLocations[i]));
        }
        context.addMapping(mapping);
    }
    if (targetClass != null) {
        context.addClass(targetClass);
    }
    return context;
}

BTW: Adding mappings multiple times will result in strange behavior because Castor tries identify objects by their namespace if it finds multiple entries with the same name and fails because of bad namespace support within castor.


Affects: 1.5.4

Referenced from: commits 73552ad

@gregturn
Copy link
Member Author

@gregturn gregturn commented Aug 28, 2008

Arjen Poutsma commented

Fixed! Thanks for spotting this.

@gregturn
Copy link
Member Author

@gregturn gregturn commented May 4, 2012

Arjen Poutsma commented

Closing old issues

@gregturn gregturn closed this May 4, 2012
@gregturn gregturn added this to the 1.5.5 milestone Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.