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

Bug 397565

Summary: Provide API to convert common object types between SWT/Java types and protocol
Product: [RT] RAP Reporter: Tim Buschtoens <tbuschto>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: tbuschto
Version: 2.0   
Target Milestone: 2.3   
Hardware: All   
OS: All   
Whiteboard:

Description Tim Buschtoens CLA 2013-01-07 08:30:20 EST
As the protocol is based on JSON, all values that are given to a set or call operation need to be converted from a Java type to a JSON type. The RemoteObject#set method is alrady overloaded for the follwing types:
int, double, boolean, String, Object.

The "call" method takes a Map, which results in the same behavior as the set method for Object. The following Object types are supported (see JSONUtil.createJsonValue): 
null, String, Byte, Short, Integer, Long, Double, Float, Boolean, int[], boolean[], Object[] (recursively).

Other types cause an IllegalArgumentException. It is not documented anywhere which Object types are supported.

For the opposite direction, the RemoteOperationHandler takes Map objects in all methods, which are based on the types returned by org.json.JSONObject#get, except that JSONArray is converted to Object[] and JSONObject is converted to Map ( both recursively).

See also ProtocolUtil.readPropertyValueAs, which can also convert to String, Point, Rectangle, int[], boolean[] and String[], but is not used for RemoteObject.

The goal of this bug is to provide a way to convert commonly used types (including SWT-specific ones like Color/RGB, Rectangle, etc) to (and possibly from) the json-compatible java-types. This mechanism could be extensible, work either implicitly or explicitly, and should document all pre-existing converters.
Comment 1 Ivan Furnadjiev CLA 2014-07-21 06:37:16 EDT
org.eclipse.rap.rwt.remote.JsonMapping has been added in RAP 2.3. Additional methods will be added to it if needed.