First, thank you very much for reading this question.
I have a JPA project and everything works fine, the json that i get with the controller is of this form:
{"id": 1, "name": "Canada"},{"id": 2, "name": "USA"}
All its fine but i would like to get a json with the Jsend standard, it something like this:
{
status : "success",
data : {
"country" : [
{"id": 1, "name": "Canada"},
{"id": 2, "name": "USA"}
]
}
}
{
"status" : "fail",
"data" : { "title" : "A title is required" }
}
{
"status" : "error",
"message" : "Unable to communicate with database"
}
As you can see i want to have a status that says success, fail or error: But i dont know how to do it. This is my DTO, DAO and Controller
@Entity
public class Country implements Serializable {
private static final long serialVersionUID = -7256468460105939L;
@Id
@Column(name="id")
private int id;
@Column(name="name")
private String name;
//Constructor, get and set
DAO
@Repository
@Transactional
public class CountryRepository {
@PersistenceContext
EntityManager entityManager;
public CountryDTO findById(int id) {
return entityManager.find(CountryDTO.class, id);
}
}
Controller
@RestController
public class CountryController {
@Autowired
CountryDTO repository;
@RequestMapping(value="api/country/{id}", method=RequestMethod.GET)
public @ResponseBody CountryDTO getByID(@PathVariable("id") int id){
return repository.findById(id);
}
}
Again thank you for your time.