Change default JSON prefix from "{} && " to ")]}', "

Issue: SPR-13078
This commit is contained in:
Sebastien Deleuze
2015-06-16 11:30:07 +02:00
parent a08c9f3137
commit 8187833502
6 changed files with 26 additions and 22 deletions

View File

@@ -48,6 +48,7 @@ import org.mozilla.javascript.Context;
import org.mozilla.javascript.ContextFactory;
import org.mozilla.javascript.ScriptableObject;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.http.MediaType;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
@@ -180,14 +181,14 @@ public class MappingJackson2JsonViewTests {
public void renderSimpleBeanPrefixed() throws Exception {
view.setPrefixJson(true);
renderSimpleBean();
assertTrue(response.getContentAsString().startsWith("{} && "));
assertTrue(response.getContentAsString().startsWith(")]}', "));
}
@Test
public void renderSimpleBeanNotPrefixed() throws Exception {
view.setPrefixJson(false);
renderSimpleBean();
assertFalse(response.getContentAsString().startsWith("{} && "));
assertFalse(response.getContentAsString().startsWith(")]}', "));
}
@Test
@@ -363,8 +364,14 @@ public class MappingJackson2JsonViewTests {
}
private void validateResult() throws Exception {
String json = response.getContentAsString();
DirectFieldAccessor viewAccessor = new DirectFieldAccessor(view);
String jsonPrefix = (String)viewAccessor.getPropertyValue("jsonPrefix");
if (jsonPrefix != null) {
json = json.substring(5);
}
Object jsResult =
jsContext.evaluateString(jsScope, "(" + response.getContentAsString() + ")", "JSON Stream", 1, null);
jsContext.evaluateString(jsScope, "(" + json + ")", "JSON Stream", 1, null);
assertNotNull("Json Result did not eval as valid JavaScript", jsResult);
assertEquals("application/json", response.getContentType());
}