@Test public void shouldIncludeCallbackPadding() { String expectedResult = "myCallback({\"order\": {\"price\": 15.0,\"comments\": \"pack it nicely, please\"}})"; Order order = new Order(15.0, "pack it nicely, please"); serialization.withCallback("myCallback").from(order).serialize(); assertThat(result(), is(equalTo(expectedResult))); }
public JSONSerialization withCallback(final String callbackName) { return new XStreamJSONSerialization(response, extractor, initializer, builder) { @Override protected SerializerBuilder getSerializer() { try { final PrintWriter writer = response.getWriter(); final StringWriter out = new StringWriter(); return new XStreamSerializer(super.getXStream(), new PrintWriter(out), extractor, initializer) { @Override public void serialize() { super.serialize(); writer.append(callbackName).append("(").append(out.getBuffer()).append(")"); writer.close(); } }; } catch (IOException e) { throw new ResultException("Unable to serialize data", e); } } }; }
XStreamJSONPSerialization implements JSONPSerialization { public JSONSerialization withCallback(final String callbackName) { return new XStreamJSONSerialization(response, extractor, initializer, builder) { @Override protected SerializerBuilder getSerializer() { try { final PrintWriter writer = response.getWriter(); final StringWriter out = new StringWriter(); return new XStreamSerializer(super.getXStream(), new PrintWriter(out), extractor, initializer) { @Override public void serialize() { super.serialize(); writer.append(callbackName).append("(").append(out.getBuffer()).append(")"); writer.close(); } }; } catch (IOException e) { throw new ResultException("Unable to serialize data", e); } } }; } }
XStreamJSONPSerialization implements JSONPSerialization { public JSONSerialization withCallback(final String callbackName) { return new XStreamJSONSerialization(response, extractor, initializer, builder) { @Override protected SerializerBuilder getSerializer() { try { final PrintWriter writer = response.getWriter(); final StringWriter out = new StringWriter(); return new XStreamSerializer(super.getXStream(), new PrintWriter(out), extractor, initializer) { @Override public void serialize() { super.serialize(); writer.append(callbackName).append("(").append(out.getBuffer()).append(")"); writer.close(); } }; } catch (IOException e) { throw new ResultException("Unable to serialize data", e); } } }; } XStreamJSONPSerialization(HttpServletResponse response, TypeNameExtractor extractor, ProxyInitializer initializer, XStreamBuilder builder); }
XStreamJSONPSerialization implements JSONPSerialization { public JSONSerialization withCallback(final String callbackName) { return new XStreamJSONSerialization(response, extractor, initializer, builder) { @Override protected SerializerBuilder getSerializer() { try { final PrintWriter writer = response.getWriter(); final StringWriter out = new StringWriter(); return new XStreamSerializer(super.getXStream(), new PrintWriter(out), extractor, initializer) { @Override public void serialize() { super.serialize(); writer.append(callbackName).append("(").append(out.getBuffer()).append(")"); writer.close(); } }; } catch (IOException e) { throw new ResultException("Unable to serialize data", e); } } }; } XStreamJSONPSerialization(HttpServletResponse response, TypeNameExtractor extractor, ProxyInitializer initializer, XStreamBuilder builder); JSONSerialization withCallback(final String callbackName); }
XStreamJSONPSerialization implements JSONPSerialization { public JSONSerialization withCallback(final String callbackName) { return new XStreamJSONSerialization(response, extractor, initializer, builder) { @Override protected SerializerBuilder getSerializer() { try { final PrintWriter writer = response.getWriter(); final StringWriter out = new StringWriter(); return new XStreamSerializer(super.getXStream(), new PrintWriter(out), extractor, initializer) { @Override public void serialize() { super.serialize(); writer.append(callbackName).append("(").append(out.getBuffer()).append(")"); writer.close(); } }; } catch (IOException e) { throw new ResultException("Unable to serialize data", e); } } }; } XStreamJSONPSerialization(HttpServletResponse response, TypeNameExtractor extractor, ProxyInitializer initializer, XStreamBuilder builder); JSONSerialization withCallback(final String callbackName);  }