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

Intermediate element not created when setting child projection #52

Open
zhsc opened this issue Apr 12, 2018 · 1 comment
Open

Intermediate element not created when setting child projection #52

zhsc opened this issue Apr 12, 2018 · 1 comment

Comments

@zhsc
Copy link

zhsc commented Apr 12, 2018

I'm seeing an issue where when using @XBWrite the last element in the path isn't created.

Here's a test case to explain what I mean.

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.xmlbeam.XBProjector;
import org.xmlbeam.XBProjector.Flags;
import org.xmlbeam.annotation.XBWrite;

public class TestSetChildOnEmptyParent {

	public interface Child {
		@XBWrite("ChildData")
		void setData(String data);
	}
	
	public interface ParentWithRootElement {
		@XBWrite("Root/ParentData")
		void setData(String data);
		
		@XBWrite("Root/Child")
		void setChild(Child child);
	}

	@Test
	public void testSetChildProjectionEmptyParent() {
		XBProjector projector = new XBProjector(Flags.TO_STRING_RENDERS_XML);
		
		ParentWithRootElement parent = projector.projectEmptyDocument(ParentWithRootElement.class);
		
		Child child = projector.projectEmptyDocument(Child.class);
		child.setData("child data...");		
		
		parent.setChild(child);  
		
		System.out.println("Result: " + parent);
		
		// Doesn't generate <Child> intermediate level
		assertEquals( 
				  "<Root>\n"
				+ "   <Child>\n"
				+ "      <ChildData>child data...</ChildData>\n"
				+ "   </Child>\n"
				+ "</Root>",
				parent.toString());
	}
	
}
@SvenEwald
Copy link
Owner

Like #51, I have a workaround:
Use
Child child = projector.projectEmptyElement("Child",Child.class);
instead of
Child child = projector.projectEmptyDocument(Child.class);

Again, I will try to make easier working with document projections and element projections.

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

2 participants