415 Unsupported Media Type
1. Basic user controller added 2. POST API explains the how to support differnet content-type formats
This commit is contained in:
parent
ec6f5d90cc
commit
1c38ab94a1
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.unsupportedmediatype;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class UnsupportedMediaTypeApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(UnsupportedMediaTypeApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.baeldung.unsupportedmediatype;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.Serializable;
|
||||
|
||||
@XmlRootElement
|
||||
public class User implements Serializable {
|
||||
private Integer id;
|
||||
private String name;
|
||||
private Integer age;
|
||||
private String address;
|
||||
|
||||
public User(Integer id, String name, Integer age, String address){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"id=" + id +
|
||||
", name='" + name + '\'' +
|
||||
", age=" + age +
|
||||
", address='" + address + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.baeldung.unsupportedmediatype;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
@GetMapping(value = "/")
|
||||
List<User> getAllUsers(){
|
||||
return Collections.singletonList(new User(1, "Andy", 28, "14th Street"));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{user-id}")
|
||||
User getUser(@PathVariable("user-id") Integer userId){
|
||||
return new User(userId, "Andy", 28, "14th Street");
|
||||
}
|
||||
|
||||
@PostMapping(value = "/", consumes = {MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE})
|
||||
void AddUser(@RequestBody User user){
|
||||
// Adding the User in the repository
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue