Try OpenEdge Now
skip to main content
Configuration
Configuring third-party Web applications : OpenEdge Management REST API framework : REST handler method response
 

REST handler method response

Each REST handler method must send a response or throw an exception. The method may handle the response or allow the framework to convert the method return value to a JSON string. All responses are can be Content-Type specified as application/JSON. Though this is not mandatory, the handler method must handle the HTTP Content-Type header and response body.
The response from a method can be one of the following types:
*String — If the type of object returned from the method is String, it is returned as-is with no validity checks. The method must ensure that the string is a properly formatted JSON encoded string.
*ObjectNode — If the type of object returned from the method is ObjectNode, a part of Jackson JSON library, the framework serializes it and writes it back to the client.
*Plain old Java object — If the type of object returned from the method is a Java object, the framework attempts to convert it to a JSON encoded string using the built-in Jackson library. If the object cannot be converted to a JSON encoded string, an HTTP 500 Internal Server Error is returned to the client, and the exception is recorded in the fathom error log file.
Note: Returning a string or an ObjectNode is quicker than returning a Java object because the latter avoids using reflection to serialize the object.
For details about Jackson capabilities, see https://github.com/FasterXML/jackson.
An example of a method returning String:
@RequestMapping(path = "/get", method = RequestMethod.GET)
public Object getSample(@QueryParam("id") String idFromQuery) {
    return "{ \"id\" : \"someid\"}";
}
An example of a method returning ObjectNode:
@RequestMapping(path = "/get", method = RequestMethod.GET)
public Object getSample(@QueryParam("id") String idFromQuery) {
    ObjectMapper mapper = new ObjectMapper();
    ObjectNode resp = mapper.createObjectNode();
    resp.put("id", "someid");
 
    return resp;
}
An example of a method returning Plain old Java object:
@RequestMapping(path = "/get", method = RequestMethod.GET)
public Object getSample(@QueryParam("id") String idFromQuery) {
 
    MyThing thing = new MyThing();
    thing.setId("someid");
 
    return thing;
}