Is your feature request related to a problem? Please describe.
I expect that a Page I deserialize using the PageJacksonModule has Object equality with an equivalent Page constructed via new PageImpl<>(). I discovered it did not when debugging a test, similar to the one included below.
Describe the solution you'd like
org.springframework.cloud.openfeign.support.PageJacksonModule.SimplePageImpl could override equals, hashCode, and toString by delegating the implementation of these methods to the delegate field. I am glad to be corrected if I'm overlooking some side-effect from this change.
Describe alternatives you've considered I could use a recursive comparison when testing for equality between Pages when at least one of the Pages is an instance of SimplePageImpl. The main objection to this alternative is that it is confusing, when "regular" equality suffices in other cases.
Additional context Test that fails, but would succeed if the proposed change is implemented:
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.cloud.openfeign.support.PageJacksonModule;
import org.springframework.cloud.openfeign.support.SortJacksonModule;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.util.List;
public class IssueTest {
@Test
void deserializingAPageWorksAsExpected() throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper()
.registerModule(new PageJacksonModule())
.registerModule(new SortJacksonModule());
String actualJson = """
{
"content": [
{
"name": "resource1"
}
],
"pageable": {
"sort": {
"empty": false,
"sorted": true,
"unsorted": false
},
"offset": 1,
"pageSize": 1,
"pageNumber": 1,
"unpaged": false,
"paged": true
},
"totalPages": 8,
"totalElements": 8,
"last": false,
"size": 1,
"number": 1,
"sort": {
"empty": false,
"sorted": true,
"unsorted": false
},
"numberOfElements": 1,
"first": false,
"empty": false
}""";
record Resource(String name) {}
Page<Resource> actual = objectMapper.readValue(actualJson, new TypeReference<>() {});
Page<Resource> expected = new PageImpl<>(List.of(new Resource("resource1")), PageRequest.of(1, 1), 8);
Assertions.assertEquals(expected, actual);
}
}
Comment From: OlgaMaciaszek
@hgjd Thanks for reporting this. Makes sense. Will add it.