I'm trying JSONP response by using @ControllerAdvice. But unnecessary comment appears before callback function name.
build.gradle
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web:1.2.7.RELEASE'
}
Application
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Controller
@RestController
public class Controller {
@ControllerAdvice
public static class JsonpAdvice extends AbstractJsonpResponseBodyAdvice {
public JsonpAdvice() {
super("callback");
}
}
@RequestMapping("/product")
public Product product(@RequestParam(value = "callback", required = false) String callback) {
return new Product(1, "foo", 100);
}
}
Product
public class Product {
int id;
String name;
int price;
public int getId() {
return id;
}
/* getters, setters, constructor */
}
Result http://localhost:8080/product?callback=callback
/**/callback({"id":1,"name":"foo","price":100});
How can I remove /**/ before callback?
Thanks.