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

Enable setUnmarshalListener on XMLBinder #2283

Open
plutext opened this issue Oct 15, 2024 · 0 comments
Open

Enable setUnmarshalListener on XMLBinder #2283

plutext opened this issue Oct 15, 2024 · 0 comments

Comments

@plutext
Copy link

plutext commented Oct 15, 2024

This has been possible in the past via reflection:

		// get xmlBinder field
		org.eclipse.persistence.jaxb.JAXBBinder jaxbBinder = (JAXBBinder)binder; 
		Field f = jaxbBinder.getClass().getDeclaredField("xmlBinder"); //NoSuchFieldException
		f.setAccessible(true);
		XMLBinder binderImpl = (XMLBinder)f.get(jaxbBinder);
		
		Field f2 = binderImpl.getClass().getDeclaredField("unmarshaller"); //NoSuchFieldException
		f2.setAccessible(true);
		org.eclipse.persistence.oxm.XMLUnmarshaller u  = (XMLUnmarshaller)f2.get(binderImpl);	
		u.setUnmarshalListener(moxyListener);
		
		// there is also SAXUnmarshaller, which wraps an unmarshaller
		Field f3 = binderImpl.getClass().getDeclaredField("saxUnmarshaller"); //NoSuchFieldException
		f3.setAccessible(true);
		org.eclipse.persistence.internal.oxm.record.SAXUnmarshaller saxUnmarshaller  = (SAXUnmarshaller)f3.get(binderImpl);
		
		Field f4 = saxUnmarshaller.getClass().getDeclaredField("xmlUnmarshaller"); //NoSuchFieldException
		f4.setAccessible(true);
		org.eclipse.persistence.internal.oxm.Unmarshaller u2  = (org.eclipse.persistence.internal.oxm.Unmarshaller)f2.get(binderImpl);	
		u2.setUnmarshalListener(moxyListener);

but these days is more likely to fail:

java.lang.reflect.InaccessibleObjectException: Unable to make field private org.eclipse.persistence.oxm.XMLBinder org.eclipse.persistence.jaxb.JAXBBinder.xmlBinder accessible: module org.eclipse.persistence.moxy does not "opens org.eclipse.persistence.jaxb" to module org.docx4j.JAXB_MOXy
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
	at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
	at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:178)
	at java.base/java.lang.reflect.Field.setAccessible(Field.java:172)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant