Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EclipseLink/Development/2.4.0/ResourceModel
Contents
EclipseLink Resource Model
The EclipseLink Resource Model defines the structure of objects marshalled and unmarshalled with XML or JSON when used in a JAX-RS service. By default the JAXB marshaller will return the entire accessible graph of what is returned from the JAX-RS method call. While this approach is functional it is very naive and may not provide a proper resource model required by REST.
Requirements
- Specify the resource scope of an object that will be marshalled or unmarshalled with a JAX-RS method call
- JPA Models with MOXy mappings
- MOXy mapped models
- All relationships not included in the resource should return a link URI to retrieve the referenced resource
- (Advanced) Using header properties allow alternate resource model definitions to be returned and consumed.
Usage Examples
The following usage examples are intended to demonstrate how the resource model can be defined and used. While these examples may imply a design they are intended to drive conversation and lead to a solution.
Static JPA Models
In this case the developer has a static Java model mapped using JPA. These entity types will be used with JAX-RS calls with either XML or JSON media type.
Example using AttributeGroup
@Entity @FetchGroup(name="default-fetch-group", attributes={ @FetchAttribute(name="id"), @FetchAttribute(name="name"), @FetchAttribute(name="address")}) @DefaultResource("default-fetch-group") public class Person { @Id private int id; private String name; @OneToOne(fetch=LAZY) private Address address;
Static MOXy Models
In this case the developer has a static Java domain model which is mapped implicitly or explicitly using MOXy and the model's classes will be used in JAX-RS calls. The resource model will define the scope and usage of links with both XML and JSON media types.
Dynamic JPA Models
Dynamic MOXy Models
Similar to the MOXy model case except there is only an eclipselink-oxm.xml mapping file that defines the dynamic mapped java classes.