Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'org.springframework.boot' version '3.5.11'
id 'org.springframework.boot' version '4.0.3'
id 'io.spring.dependency-management' version '1.1.7'
id 'java'
id "au.com.dius.pact" version "4.6.20"
Expand Down
25 changes: 6 additions & 19 deletions src/main/java/com/example/products/ProductClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import org.apache.http.client.fluent.Request;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import tools.jackson.core.type.TypeReference;
import tools.jackson.databind.ObjectMapper;

import java.io.IOException;
import java.util.List;
Expand All @@ -22,29 +21,17 @@ public Product getProduct(String id) throws IOException {
return (Product) Request.Get(this.url + "/product/" + id)
.addHeader("Accept", "application/json")
.execute().handleResponse(httpResponse -> {
try {
ObjectMapper mapper = new ObjectMapper();
Product product = mapper.readValue(httpResponse.getEntity().getContent(), Product.class);

return product;
} catch (JsonMappingException e) {
throw new IOException(e);
}
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(httpResponse.getEntity().getContent(), Product.class);
});
}

public List<Product> getProducts() throws IOException {
return (List<Product>) Request.Get(this.url + "/products")
.addHeader("Accept", "application/json")
.execute().handleResponse(httpResponse -> {
try {
ObjectMapper mapper = new ObjectMapper();
List<Product> products = mapper.readValue(httpResponse.getEntity().getContent(), new TypeReference<List<Product>>(){});

return products;
} catch (JsonMappingException e) {
throw new IOException(e);
}
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(httpResponse.getEntity().getContent(), new TypeReference<List<Product>>(){});
});
}
}