# Class JsonMapping

java.lang.Object
org.eclipse.rap.rwt.remote.JsonMapping

public class JsonMapping extends Object
Provides utility methods that map common SWT types to their JSON representations used in the RAP protocol and back.

Since:
  2.3
See Also:
  - http://wiki.eclipse.org/RAP/Protocol

## Method Summary

Modifier and Type
Method
Description
`static Point`
`readPoint(JsonValue value)`
Returns an instance of Point for the given JSON representation.
`static Rectangle`
`readRectangle(JsonValue value)`
Returns an instance of Rectangle for the given JSON representation.
`static RGB`
`readRGB(JsonValue value)`
Returns an instance of RGB for the given JSON representation.
`static JsonValue`
`toJson(Color color)`
Returns the JSON representation for the given Color.
`static JsonValue`
`toJson(Color color, int alpha)`
Returns the JSON representation for the given Color with an additional alpha (opacity) value.
`static JsonValue`
`toJson(Cursor cursor)`
Returns the JSON representation for the given Cursor.
`static JsonValue`
`toJson(Font font)`
Returns the JSON representation for the given Font.
`static JsonValue`
`toJson(FontData fontData)`
Returns the JSON representation for the given FontData.
`static JsonValue`
`toJson(Image image)`
Returns the JSON representation for the given Image.
`static JsonValue`
`toJson(Point point)`
Returns the JSON representation for the given Point.
`static JsonValue`
`toJson(Point[] points)`
Returns the JSON representation for the given array Point.
`static JsonValue`
`toJson(Rectangle rect)`
Returns the JSON representation for the given Rectangle.
`static JsonValue`
`toJson(RGB rgb)`
Returns the JSON representation for the given RGB.
`static JsonValue`
`toJson(RGB rgb, int alpha)`
Returns the JSON representation for the given RGB with an additional alpha (opacity) value.
`static JsonValue`
`toJson(Widget widget)`
Returns the JSON representation for the given Widget.
`static JsonValue`
`toJson(Widget[] widgets)`
Returns the JSON representation for the given array of widgets.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### toJson

public static JsonValue toJson(Widget widget)
Returns the JSON representation for the given Widget. This method accepts `null`, which will be mapped to `JsonValue.NULL`. Disposed widgets cannot be mapped to JSON.

Parameters:
  `widget` - the widget to encode or `null`, must not be disposed
Returns:
  a JSON value that represents the given widget

### toJson

public static JsonValue toJson(Widget[] widgets)
Returns the JSON representation for the given array of widgets. The array must not contain disposed widgets, as those cannot be mapped to JSON.

Parameters:
  `widgets` - the array of widgets to encode, must not be `null`
Returns:
  a JSON value that represents the given widget array
Since:
  3.1

### toJson

public static JsonValue toJson(Point point)
Returns the JSON representation for the given Point. This method accepts `null`, which will be mapped to `JsonValue.NULL`.

Parameters:
  `point` - the Point to encode or `null`
Returns:
  a JSON value that represents the given point

### toJson

public static JsonValue toJson(Point[] points)
Returns the JSON representation for the given array Point. This method accepts `null`, which will be mapped to `JsonValue.NULL`.

Parameters:
  `points` - the array Point to encode or `null`
Returns:
  a JSON value that represents the given point
Since:
  3.13

### toJson

public static JsonValue toJson(Rectangle rect)
Returns the JSON representation for the given Rectangle. This method accepts `null`, which will be mapped to `JsonValue.NULL`.

Parameters:
  `rect` - the Rectangle to encode or `null`
Returns:
  a JSON value that represents the given rectangle

### toJson

public static JsonValue toJson(Color color)
Returns the JSON representation for the given Color. This method accepts `null`, which will be mapped to `JsonValue.NULL`. Disposed colors cannot be mapped to JSON.

Parameters:
  `color` - the Color to encode or `null`, must not be disposed
Returns:
  a JSON value that represents the given color

### toJson

public static JsonValue toJson(Color color, int alpha)
Returns the JSON representation for the given Color with an additional alpha (opacity) value. This method accepts `null`, which will be mapped to `JsonValue.NULL` regardless of the given alpha value. Disposed colors cannot be mapped to JSON.

Parameters:
  `color` - the Color to encode or `null`, must not be disposed
  `alpha` - a value in the range of 0 (transparent) to 255 (opaque)
Returns:
  a JSON value that represents the given color

### toJson

public static JsonValue toJson(RGB rgb)
Returns the JSON representation for the given RGB. This method accepts `null`, which will be mapped to `JsonValue.NULL`.

Parameters:
  `rgb` - the Color to encode or `null`
Returns:
  a JSON value that represents the given color

### toJson

public static JsonValue toJson(RGB rgb, int alpha)
Returns the JSON representation for the given RGB with an additional alpha (opacity) value. This method accepts `null`, which will be mapped to `JsonValue.NULL` regardless of the given alpha value.

Parameters:
  `rgb` - the RGB to encode or `null`
  `alpha` - a value in the range of 0 (transparent) to 255 (opaque)
Returns:
  a JSON value that represents the given rgb

### toJson

public static JsonValue toJson(Image image)
Returns the JSON representation for the given Image. This method accepts `null`, which will be mapped to `JsonValue.NULL`. Disposed images cannot be mapped to JSON.

Parameters:
  `image` - the Image to encode or `null`, must not be disposed
Returns:
  a JSON value that represents the given rgb

### toJson

public static JsonValue toJson(Font font)
Returns the JSON representation for the given Font. This method accepts `null`, which will be mapped to `JsonValue.NULL`. Disposed fonts cannot be mapped to JSON.

Parameters:
  `font` - the Font to encode or `null`, must not be disposed
Returns:
  a JSON value that represents the given font

### toJson

public static JsonValue toJson(FontData fontData)
Returns the JSON representation for the given FontData. This method accepts `null`, which will be mapped to `JsonValue.NULL`.

Parameters:
  `fontData` - the FontData to encode or `null`
Returns:
  a JSON value that represents the given font data

### toJson

public static JsonValue toJson(Cursor cursor)
Returns the JSON representation for the given Cursor. This method accepts `null`, which will be mapped to `JsonValue.NULL`.

Parameters:
  `cursor` - the Cursor to encode or `null`
Returns:
  a JSON value that represents the given cursor
Since:
  3.1

### readPoint

public static Point readPoint(JsonValue value)
Returns an instance of Point for the given JSON representation. This method returns `null` if the given JSON value is `JsonValue.NULL`.

Parameters:
  `value` - a JsonValue that represents a point or `JsonValue.NULL`
Returns:
  a Point that corresponds to the given JSON value or `null`

### readRectangle

public static Rectangle readRectangle(JsonValue value)
Returns an instance of Rectangle for the given JSON representation. This method returns `null` if the given JSON value is `JsonValue.NULL`.

Parameters:
  `value` - a JsonValue that represents a rectangle or `JsonValue.NULL`
Returns:
  a Rectangle that corresponds to the given JSON value or `null`

### readRGB

public static RGB readRGB(JsonValue value)
Returns an instance of RGB for the given JSON representation. This method returns `null` if the given JSON value is `JsonValue.NULL`.

Parameters:
  `value` - a JsonValue that represents a color or `JsonValue.NULL`
Returns:
  an RGB that corresponds to the given JSON value or `null`