Remove JSONP support

CORS is now widely supported and should be used instead for cross-domain
requests.

Issue: SPR-16914
This commit is contained in:
Sebastien Deleuze
2018-06-07 11:33:25 +02:00
parent 19dc981685
commit ac37b678a3
23 changed files with 25 additions and 713 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,21 +95,6 @@ public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMes
if (this.jsonPrefix != null) {
generator.writeRaw(this.jsonPrefix);
}
String jsonpFunction =
(object instanceof MappingJacksonValue ? ((MappingJacksonValue) object).getJsonpFunction() : null);
if (jsonpFunction != null) {
generator.writeRaw("/**/");
generator.writeRaw(jsonpFunction + "(");
}
}
@Override
protected void writeSuffix(JsonGenerator generator, Object object) throws IOException {
String jsonpFunction =
(object instanceof MappingJacksonValue ? ((MappingJacksonValue) object).getJsonpFunction() : null);
if (jsonpFunction != null) {
generator.writeRaw(");");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,9 +45,6 @@ public class MappingJacksonValue {
@Nullable
private FilterProvider filters;
@Nullable
private String jsonpFunction;
/**
* Create a new instance wrapping the given POJO to be serialized.
@@ -113,19 +110,4 @@ public class MappingJacksonValue {
return this.filters;
}
/**
* Set the name of the JSONP function name.
*/
public void setJsonpFunction(@Nullable String functionName) {
this.jsonpFunction = functionName;
}
/**
* Return the configured JSONP function name.
*/
@Nullable
public String getJsonpFunction() {
return this.jsonpFunction;
}
}

View File

@@ -394,39 +394,6 @@ public class MappingJackson2HttpMessageConverterTests {
assertThat(result, not(containsString("\"property2\":\"value\"")));
}
@Test
public void jsonp() throws Exception {
MappingJacksonValue jacksonValue = new MappingJacksonValue("foo");
jacksonValue.setSerializationView(MyJacksonView1.class);
jacksonValue.setJsonpFunction("callback");
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
this.converter.writeInternal(jacksonValue, null, outputMessage);
assertEquals("/**/callback(\"foo\");", outputMessage.getBodyAsString(StandardCharsets.UTF_8));
}
@Test
public void jsonpAndJsonView() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
JacksonViewBean bean = new JacksonViewBean();
bean.setWithView1("with");
bean.setWithView2("with");
bean.setWithoutView("without");
MappingJacksonValue jacksonValue = new MappingJacksonValue(bean);
jacksonValue.setSerializationView(MyJacksonView1.class);
jacksonValue.setJsonpFunction("callback");
this.converter.writeInternal(jacksonValue, null, outputMessage);
String result = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(result, startsWith("/**/callback("));
assertThat(result, endsWith(");"));
assertThat(result, containsString("\"withView1\":\"with\""));
assertThat(result, not(containsString("\"withView2\":\"with\"")));
assertThat(result, not(containsString("\"withoutView\":\"without\"")));
}
@Test // SPR-13318
public void writeSubType() throws Exception {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();