From 8396dabf774f1b66bc8a74015b2b6385fc105af3 Mon Sep 17 00:00:00 2001 From: Azhwani Date: Sun, 17 Jan 2021 02:27:34 +0100 Subject: [PATCH] quick fix --- .../resttemplateexception/controller/ProductApi.java | 6 +----- .../RestTemplateExceptionLiveTest.java | 6 ------ 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java index 66fbfa487d..2c530cae2b 100644 --- a/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java +++ b/spring-web-modules/spring-resttemplate-2/src/main/java/com/baeldung/resttemplateexception/controller/ProductApi.java @@ -23,11 +23,8 @@ public class ProductApi { @GetMapping("/get") public Product get(@RequestParam String criterion) throws JsonMappingException, JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); - Criterion crt; - - crt = objectMapper.readValue(criterion, Criterion.class); + Criterion crt = objectMapper.readValue(criterion, Criterion.class); if (crt.getProp().equals("name")) return findByName(crt.getValue()); @@ -46,5 +43,4 @@ public class ProductApi { } // Other methods - } diff --git a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java index f5938e1f0a..adfb8ffa4e 100644 --- a/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java +++ b/spring-web-modules/spring-resttemplate-2/src/test/java/com/baeldung/resttemplateexception/RestTemplateExceptionLiveTest.java @@ -21,26 +21,21 @@ public class RestTemplateExceptionLiveTest { @Test(expected = IllegalArgumentException.class) public void givenGetUrl_whenJsonIsPassed_thenThrowException() { - String url = "http://localhost:8080/spring-rest/api/get?criterion={\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}"; Product product = restTemplate.getForObject(url, Product.class); - } @Test public void givenGetUrl_whenJsonIsPassed_thenGetProduct() { - String criterion = "{\"prop\":\"name\",\"value\":\"ASUS VivoBook\"}"; String url = "http://localhost:8080/spring-rest/api/get?criterion={criterion}"; Product product = restTemplate.getForObject(url, Product.class, criterion); assertEquals(product.getPrice(), 650, 0); - } @Test public void givenGetUrl_whenJsonIsPassed_thenReturnProduct() { - String criterion = "{\"prop\":\"name\",\"value\":\"Acer Aspire 5\"}"; String url = "http://localhost:8080/spring-rest/api/get"; @@ -48,6 +43,5 @@ public class RestTemplateExceptionLiveTest { Product product = restTemplate.getForObject(builder.build().toUri(), Product.class); assertEquals(product.getId(), 1, 0); - } }