There is spring-boot application(web+jpa) So, I have controller:
@RestController
public class CustomerController {
@Autowired
private CustomerService customerService;
@RequestMapping(value = "/customers", method = RequestMethod.GET)
public @ResponseBody List<Customer> findAllCustomers() {
return customerService.findAllCustomers();
}
@RequestMapping(value = "/customers", method = RequestMethod.POST)
public void addCustomer(@RequestBody Customer customer) {
customerService.addCustomer(customer);
}
Model:
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name="customer")
@XmlRootElement(name="customer")
public class Customer{
@Id
private String id;
private String name;
public Customer(String id, String name) {
this.id = id;
this.name = name;
}
public Customer() {
}
public String getId() {
return id;
}
@XmlElement
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
}
}
And service layer for bind jpa and rest.
When I do request:
<customer>
<id>first</id>
<name>first name of metric</name>
</customer>
it's okey, customer added in database, but, when I try to get all customers, the response in json format, but I expected xml. How to fix it issue?