Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 338548

Summary: XmlAccessorType.NONE being ignored
Product: z_Archived Reporter: clittleton
Component: EclipselinkAssignee: Matt MacIvor <matt.macivor>
Status: RESOLVED FIXED QA Contact:
Severity: major    
Priority: P3 CC: matt.macivor
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
test case
none
Propsed Fix and Updated Tests none

Description clittleton CLA 2011-03-01 10:43:40 EST
Build Identifier: Eclipse Persistence Services - 2.3.0.v20110225-r9029

If you have a domain object that has a field of a type which does not have a zero argument constructor then you will get the exception for this class even if you have XmlAccessorType.NONE and the field is not mapped or annotated. It seems like MOXy is introspecting the domain objects deeply and trying to construct everything even if the members are not needed (due to being transient).
 
I have attached a sample of the code that will reproduce the problem. In the class Bar, if there is no zero argument constructor then the marshalling will not work. You can uncomment the empty constructor to see that it will work in that case. Note that in my oxm.xml file I have only mapped "field1" and not "bar", so there should be no reason for the Bar class to be referenced or instantiated.

package com.test;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;

@XmlAccessorType(XmlAccessType.NONE)
public class Bar {

//	public Bar(){}
	
	public Bar(String value){}
}
package com.test;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlTransient;

@XmlAccessorType(XmlAccessType.NONE)
public class Foo {

	private String field1;
	private String field2;
	@XmlTransient
	private Bar bar;
	
	public Foo(String string){}

	public String getField1() {
		return field1;
	}
	
	public void setField1(String field1) {
		this.field1 = field1;
	}
	
	public String getField2() {
		return field2;
	}
	
	public void setField2(String field2) {
		this.field2 = field2;
	}

	public Bar getBar() {
		return bar;
	}

	public void setBar(Bar bar) {
		this.bar = bar;
	}		
}

<?xml version="1.0"?>
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
	version="2.1">
	<java-types>
		<java-type name="com.test.Foo" xml-accessor-type="NONE">
			<java-attributes>
				<xml-element java-attribute="field" />
			</java-attributes>
		</java-type>


	</java-types>
</xml-bindings>

Reproducible: Always
Comment 1 clittleton CLA 2011-03-01 11:09:49 EST
Created attachment 190045 [details]
test case

This is a test case which exhibits the bug.
Comment 2 Matt MacIvor CLA 2011-03-03 14:17:38 EST
Created attachment 190302 [details]
Propsed Fix and Updated Tests
Comment 3 Matt MacIvor CLA 2011-03-07 09:53:06 EST
Attached patch checked in to SVN
Reviewed by Blaise Doughan
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:10:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:16:57 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink