Serializes the given object and wraps it in a callback function i.e. <callback>(<json>) Note: This will not append a trailing semicolon @param callback The name of the Javascript callback to prepend @param object The object to serialize @return A JSONP formatted string @throws IllegalArg
(final String callback,
final Object object)
| 309 | * @throws JSONException if the object could not be serialized |
| 310 | */ |
| 311 | public static final String serializeToJSONPString(final String callback, |
| 312 | final Object object) { |
| 313 | if (callback == null || callback.isEmpty()) |
| 314 | throw new IllegalArgumentException("Missing callback name"); |
| 315 | if (object == null) |
| 316 | throw new IllegalArgumentException("Object was null"); |
| 317 | try { |
| 318 | return jsonMapper.writeValueAsString(new JSONPObject(callback, object)); |
| 319 | } catch (JsonProcessingException e) { |
| 320 | throw new JSONException(e); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * Serializes the given object and wraps it in a callback function |