Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/MOXy/Type Level/Handling Inheritance"

m (New page: = Handling Inheritance = == Using xsi:type Attribute == You can use the '''xsi:type''' attribute to represent inheritance in JAXB. In this example an abstract super class ('''ContactIn...)
 
m (Replacing page with 'Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm')
 
(24 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Handling Inheritance =
+
Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm
 
+
== Using xsi:type Attribute ==
+
 
+
You can use the '''xsi:type''' attribute to represent inheritance in JAXB.  
+
 
+
In this example an abstract super class ('''ContactInfo'') contains all types of contact information. '''Address''' and '''PhoneNumber''' are the concrete implementations of '''ContactInfo'''.
+
 
+
<source lang="java">
+
package blog.inheritance;
+
+
public abstract class ContactInfo {
+
+
}
+
 
+
public class Address extends ContactInfo {
+
+
    private String street;
+
+
    public String getStreet() {
+
        return street;
+
    }
+
+
    public void setStreet(String street) {
+
        this.street = street;
+
    }
+
+
}
+
 
+
public class PhoneNumber extends ContactInfo {
+
+
}
+
 
+
</source>
+
 
+
 
+
Because the '''Customer''' object can have different types of contact information, its property refers to the superclass.
+
 
+
<source lang="java">
+
package blog.inheritance;
+
+
import javax.xml.bind.annotation.XmlRootElement;
+
+
@XmlRootElement
+
public class Customer {
+
+
    private ContactInfo contactInfo;
+
+
    public ContactInfo getContactInfo() {
+
        return contactInfo;
+
    }
+
+
    public void setContactInfo(ContactInfo contactInfo) {
+
        this.contactInfo = contactInfo;
+
    }
+
+
}
+
</source>
+

Latest revision as of 08:50, 8 November 2012

Please see http://www.eclipse.org/eclipselink/documentation/2.4/moxy/type_level003.htm