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 byte array @throws Illega
(final String callback,
final Object object)
| 333 | * @throws JSONException if the object could not be serialized |
| 334 | */ |
| 335 | public static final byte[] serializeToJSONPBytes(final String callback, |
| 336 | final Object object) { |
| 337 | if (callback == null || callback.isEmpty()) |
| 338 | throw new IllegalArgumentException("Missing callback name"); |
| 339 | if (object == null) |
| 340 | throw new IllegalArgumentException("Object was null"); |
| 341 | try { |
| 342 | return jsonMapper.writeValueAsBytes(new JSONPObject(callback, object)); |
| 343 | } catch (JsonProcessingException e) { |
| 344 | throw new JSONException(e); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Returns a reference to the static ObjectMapper |