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

Jaxb2Marshaller + packagesToScan + SpringMVC fails to find supported class [SPR-10551] #15182

Closed
spring-projects-issues opened this issue May 10, 2013 · 0 comments
Assignees
Labels
in: data status: backported status: duplicate
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented May 10, 2013

Michael Bazos opened SPR-10551 and commented

There seems to be an issue when you use the Jaxb2Marshaller + packagesToScan in conjunction with Spring MVC.

The issue I am specifically running into is that the method returns false even though the JAXBContext knows about the class:
public boolean supports(Class<?> clazz){...}

The issue is with the following method:

private boolean supportsInternal(Class<?> clazz, boolean checkForXmlRootElement) {
	if (checkForXmlRootElement && AnnotationUtils.findAnnotation(clazz, XmlRootElement.class) == null) {
		return false;
	}
	if (StringUtils.hasLength(getContextPath())) {
		String packageName = ClassUtils.getPackageName(clazz);
		String[] contextPaths = StringUtils.tokenizeToStringArray(getContextPath(), ":");
		for (String contextPath : contextPaths) {
			if (contextPath.equals(packageName)) {
				return true;
			}
		}
		return false;
	}
	else if (!ObjectUtils.isEmpty(getClassesToBeBound())) {
		return Arrays.asList(getClassesToBeBound()).contains(clazz);
	}
	return false;
}

The problem is that even if the "packagesToScan" works...which it does the supportInternal method needs to check the current JAXBContext to see if that class is actually loaded. I checked and you cannot do this with JAXBContext so a better solution might be to add the class names to "classesToBeBound" as they are scanned in from the package scanner. After that then in the "supportsInternal" method an additional check can be made to see if the packages.

If you need me to attach code for the fix I would be more than happy to. Please just let me know as I am here to help. Also I didn't check the latest spring-oxm so I am not sure if this is no longer an issue but I couldn't find information on this in jira.


Affects: 3.1.1

Issue Links:

  • #13790 Jaxb2Marshaller::supports() ignores classes found by packages scanning ("duplicates")

Backported to: 3.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data status: backported status: duplicate
Projects
None yet
Development

No branches or pull requests

2 participants