Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » MOXy - afterUnmarshal() not called in children of lists
MOXy - afterUnmarshal() not called in children of lists [message #816609] Fri, 09 March 2012 03:27 Go to next message
Marty Pitt is currently offline Marty Pitt
Messages: 2
Registered: March 2012
Junior Member
Note - this question has been cross-posted to Stack Overflow - so, if you're a rep junkie, go grab the points!

( I can't post the link, but it's question 9628477)

I'm having trouble where the `afterUnmarshal()` methods on my classes are not called if the class is a member of a collection.

Beyond declaring the method on a class which is created via unmarshalling, is there any other steps I'm required to perform? (I can't see anything else in [the docs][1])

Here's a test which shows the problem I'm having:

Given these two domain classes:

    @XmlRootElement(name="Parent")
    public class Parent {
    
    	public boolean unmarshalCalled = false;
    	
    	@XmlPath("Children/Child")
    	List<Child> children;
    	
    	void afterUnmarshal(Unmarshaller u, Object parent)
    	{
    		unmarshalCalled = true;
    	}
    }


    @XmlAccessorType(XmlAccessType.FIELD)
    public class Child {
    
    	public boolean unmarshalCalled = false;
    	
    	@Getter @Setter
    	@XmlPath("@name")
    	private String name;
    	
    	void afterUnmarshal(Unmarshaller u, Object parent)
    	{
    		unmarshalCalled = true;
    	}
    }


This test fails:

   
    public class UnmarshalTest {
    
    	@Test
    	@SneakyThrows
    	public void testUnmarshal()
    	{
    		String xml = "<Parent><Children><Child name='Jack' /><Child name='Jill' /></Children></Parent>";
    		JAXBContext context = getContext();
    		Parent parent = (Parent) context.createUnmarshaller().unmarshal(new StringReader(xml));
    		assertTrue(parent.unmarshalCalled);
    		for (Child child : parent.children)
    		{
    			assertThat(child.getName(),notNullValue());
    			assertTrue(child.unmarshalCalled); // This assertion fails
    		}
    	}
    	@SneakyThrows
    	public static JAXBContext getContext()
    	{
    		JAXBContext context;
    		context = org.eclipse.persistence.jaxb.JAXBContext.newInstance(Parent.class);
    		return context;
    	}
    }


Is this a bug, or have I missed some steps to get this to work correctly?


Re: MOXy - afterUnmarshal() not called in children of lists [message #817126 is a reply to message #816609] Fri, 09 March 2012 17:12 Go to previous message
Blaise Doughan is currently offline Blaise Doughan
Messages: 163
Registered: July 2009
Senior Member

Hi Marty,

The issue you are seeing is due to the following EclipseLink MOXy bug:

- https://bugs.eclipse.org/364410

This bug has already been fixed in the EclipseLink 2.3.3 stream, a nightly download can be obtained from:

- http://www.eclipse.org/eclipselink/downloads/nightly.php

Workaround

You can workaround the issue that you are seeing by ensuring that all of the classes with event methods are included in the array of classes passed in to create the JAXBContext. I have modified you code below to do this:

    @SneakyThrows
    public static JAXBContext getContext()
    {
        JAXBContext context;
        context = org.eclipse.persistence.jaxb.JAXBContext.newInstance(Parent.class, Child.class);
        return context;
    }


-Blaise
Previous Topic:EclipseLink 2 on Tomcat
Next Topic:Querying the EclipseLink version at runtime?
Goto Forum:
  


Current Time: Mon Sep 22 22:35:09 GMT 2014

Powered by FUDForum. Page generated in 0.01675 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software