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

Bug 353446

Summary: Possible Bug - Behaviour difference when @XmlJavaTypeAdapter/@XmlSchemaType are used at the package and property levels
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Blaise Doughan <blaise.doughan>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: david.twelves
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Code demonstrating the bug none

Description Blaise Doughan CLA 2011-07-29 16:46:47 EDT
There is a difference in behaviour when @XmlJavaTypeAdapter and @XmlSchemaType are used together at the package and property levels.

PROPERTY LEVEL

package foo;

import java.util.Date;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

public class PropertyLevel {

    @XmlJavaTypeAdapter(DateAdapter.class)
    @XmlSchemaType(name="date")
    @XmlElement
    private Date date;

}

PACKAGE LEVEL

package foo;

import java.util.Date;

import javax.xml.bind.annotation.XmlElement;

public class PackageLevel {

    @XmlElement
    private Date date;

}

@XmlJavaTypeAdapters(
    @XmlJavaTypeAdapter(value=DateAdapter.class, type=Date.class)
)
@XmlSchemaTypes({
    @XmlSchemaType(name="date", type=Date.class)
})
package foo;

import javax.xml.bind.annotation.adapters.*;
import javax.xml.bind.annotation.*;
import java.util.Date;

---

GENERATED SCHEMA

Note how the type of the date elements is different.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="packageLevel">
    <xs:sequence>
      <xs:element name="date" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="propertyLevel">
    <xs:sequence>
      <xs:element name="date" type="xs:date" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
Comment 1 Blaise Doughan CLA 2011-07-29 17:01:30 EDT
Created attachment 200615 [details]
Code demonstrating the bug
Comment 2 Blaise Doughan CLA 2012-04-30 14:30:41 EDT
This is not a bug and is working correctly.  The package level XmlAdapter is applied to PackageLevel.date and changes the "value" type from Date to String, since the value type is now String and not Date the @XmlSchemaType specified at the package level does not apply.
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:08:13 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:14:28 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink