BAEL-4687: simplified configuration
This commit is contained in:
parent
2a8ff6f23b
commit
0218395e89
|
@ -1,7 +1,6 @@
|
|||
package com.baeldung.boot.jackson.controller;
|
||||
|
||||
import com.baeldung.boot.jackson.model.Coffee;
|
||||
import com.baeldung.boot.jackson.model.CoffeeResponse;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -12,14 +11,11 @@ import java.time.LocalDateTime;
|
|||
public class CoffeeController {
|
||||
|
||||
@GetMapping("/coffee")
|
||||
public CoffeeResponse<Coffee> createCoffee(@RequestParam(required = false) String brand,
|
||||
public Coffee getCoffee(@RequestParam(required = false) String brand,
|
||||
@RequestParam(required = false) String name) {
|
||||
Coffee coffee = new Coffee()
|
||||
return new Coffee()
|
||||
.setBrand(brand)
|
||||
.setName(name);
|
||||
|
||||
return new CoffeeResponse<Coffee>()
|
||||
.setDate(LocalDateTime.now())
|
||||
.setBody(coffee);
|
||||
.setName(name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
package com.baeldung.boot.jackson.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class Coffee {
|
||||
|
||||
private String name;
|
||||
|
||||
private String brand;
|
||||
|
||||
private LocalDateTime date;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -23,4 +27,13 @@ public class Coffee {
|
|||
this.brand = brand;
|
||||
return this;
|
||||
}
|
||||
|
||||
public LocalDateTime getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public Coffee setDate(LocalDateTime date) {
|
||||
this.date = date;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
package com.baeldung.boot.jackson.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class CoffeeResponse<T> {
|
||||
|
||||
private LocalDateTime date;
|
||||
|
||||
private T body;
|
||||
|
||||
public LocalDateTime getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public CoffeeResponse<T> setDate(LocalDateTime date) {
|
||||
this.date = date;
|
||||
return this;
|
||||
}
|
||||
|
||||
public T getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public CoffeeResponse<T> setBody(T body) {
|
||||
this.body = body;
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@ public class CoffeeIntegrationTest {
|
|||
TestRestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void whenQueryCoffeeWithoutParam_thenNullIsNotInserted() {
|
||||
public void whenGetCoffee_thenSerializedWithDateAndNonNull() {
|
||||
String formattedDate = DateTimeFormatter.ofPattern(CoffeeConfiguration.dateTimeFormat)
|
||||
.format(LocalDateTime.now());
|
||||
String brand = "Lavazza";
|
||||
|
@ -27,6 +27,6 @@ public class CoffeeIntegrationTest {
|
|||
String response = restTemplate.getForObject(url, String.class);
|
||||
|
||||
assertThat(response).isEqualTo(
|
||||
"{\"date\":\"" + formattedDate + "\",\"body\":{\"brand\":\"" + brand + "\"}}");
|
||||
"{\"brand\":\"" + brand + "\",\"date\":\"" + formattedDate + "\"}");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue