Spring JSONP with Jackson

This commit is contained in:
MafaldaLandeiro
2016-06-26 00:16:13 +01:00
parent a661e0e3c9
commit 9b30521a3f
7 changed files with 193 additions and 40 deletions

View File

@@ -0,0 +1,16 @@
package org.baeldung.web.controller;
import org.baeldung.web.dto.Company;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CompanyController {
@RequestMapping(value = "/companyRest", produces = MediaType.APPLICATION_JSON_VALUE)
public Company getCompanyRest() {
final Company company = new Company(1, "Xpto");
return company;
}
}

View File

@@ -0,0 +1,13 @@
package org.baeldung.web.controller.advice;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.AbstractJsonpResponseBodyAdvice;
@ControllerAdvice
public class JsonpControllerAdvice extends AbstractJsonpResponseBodyAdvice {
public JsonpControllerAdvice() {
super("callback");
}
}

View File

@@ -0,0 +1,38 @@
package org.baeldung.web.dto;
public class Company {
private long id;
private String name;
public Company() {
super();
}
public Company(final long id, final String name) {
this.id = id;
this.name = name;
}
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(final long id) {
this.id = id;
}
@Override
public String toString() {
return "Company [id=" + id + ", name=" + name + "]";
}
}