Junos Space SDK > Developer Guides > Junos Space Application Developer Guide > Programming with the Junos Space SDK > Developing Junos Space Applications > Creating EJBs

Guidelines for the Source Java Method's Return and Argument Types

When the EJB method is exposed as a REST service, the REST DTOs are created corresponding to the return type or argument type present in the EJB method. The REST DTO is a special POJO class that is almost identical field-wise to an the EJB method's return type (for a GET method) or argument type (for a POST or PUT method). In addition, it has an XML element annotation that enables it to be transformed into XML or JSON data when exposed as a REST resource.

For example, consider the EJB method public User getUser(int userID). When this method is RESTified as a GET method, the generated REST class will have a method as given below:

@GET
@Produces(....)
public User getUser(@PathParams params0)

Here the return type user class is a REST DTO that is automatically generated. This REST DTO is different from the return type User class of the EJB method.

When the REST services are created, the REST DTO is also configured. The EJB-REST wizard displays the REST DTO configuration page, listing all the fields present in the EJB method's return type (for a GET method) or argument type (for a POST or PUT method). You can select the fields that need to be exposed through the REST DTO. The EJB-REST wizard processes the EJB method's return type (for a GET method) or argument type (for a POST or PUT method) according to the steps given below

Simple Fields

The EJB method's return type (for a GET method) or argument type (for a POST or PUT method) may contain fields of a primitive type such as int, char, boolean, and float; and wrapper classes such as Integer, Boolean, and Float. The String type is also considered a simple type. The simple type fields are supplied with an XMLElement annotation in the REST DTO.

Example:

EJB Return Type
class User{ 
int age;
String name;
float weight;
...
} REST DTO created corresponding to the User class above class User{
@XmlElement(name="age")
int age;
@XmlElement(name="name")
String name;
@XmlElement(name="weight")
float weight;
...
}

Note: The wizard provides special handling for the data types such as enum (that are not supported in the REST framework). It generates a String type in the REST DTO for the enum type in the EJB method's return type (for a GET method) or argument type(for a POST or PUT method), and also generates a code for conversion (from enum to string and from string to enum).

java.util.Date has built-in JAXB support; hence, you can use it in your method's argument or return type and expose it in the REST DTO class directly.

Complex Fields

The fields that are not mentioned above as a simple field are complex fields. Complex fields are configured further by the EJB-REST wizard in a pop-up screen where complex fields are displayed. Some fields that are marked as RED are not supported by the EJB-REST Wizard, and they cannot be configured.

Example:

The address and role fields are complex fields in the example below. The friends field is also a complex field, but because it is not parameterized, it cannot be configured.

class User { 
int age;
String name;
float weight;
Address address;
 Collection roles;
Collection friends; // This field is not a parameterized Collection, so it is not supported
...
}

The properties of Complex Fields (also termed as pull-through fields) are further divided into two categories (termed as simple and complex). For complex fields, the wizard supports as many levels of containment as required by the user.