java 不能反序列化_JSONMappingException-无法反序列化Java对象

小编典典

我最终使用了类似的东西,按照@Perception的建议创建了一个bean:

import java.util.ArrayList;

import java.util.List;

import org.springframework.data.domain.PageImpl;

import org.springframework.data.domain.PageRequest;

import org.springframework.data.domain.Sort;

public class PageImplBean extends PageImpl {

private static final long serialVersionUID = 1L;

private int number;

private int size;

private int totalPages;

private int numberOfElements;

private long totalElements;

private boolean previousPage;

private boolean firstPage;

private boolean nextPage;

private boolean lastPage;

private List content;

private Sort sort;

public PageImplBean() {

super(new ArrayList());

}

public int getNumber() {

return number;

}

public void setNumber(int number) {

this.number = number;

}

public int getSize() {

return size;

}

public void setSize(int size) {

this.size = size;

}

public int getTotalPages() {

return totalPages;

}

public void setTotalPages(int totalPages) {

this.totalPages = totalPages;

}

public int getNumberOfElements() {

return numberOfElements;

}

public void setNumberOfElements(int numberOfElements) {

this.numberOfElements = numberOfElements;

}

public long getTotalElements() {

return totalElements;

}

public void setTotalElements(long totalElements) {

this.totalElements = totalElements;

}

public boolean isPreviousPage() {

return previousPage;

}

public void setPreviousPage(boolean previousPage) {

this.previousPage = previousPage;

}

public boolean isFirstPage() {

return firstPage;

}

public void setFirstPage(boolean firstPage) {

this.firstPage = firstPage;

}

public boolean isNextPage() {

return nextPage;

}

public void setNextPage(boolean nextPage) {

this.nextPage = nextPage;

}

public boolean isLastPage() {

return lastPage;

}

public void setLastPage(boolean lastPage) {

this.lastPage = lastPage;

}

public List getContent() {

return content;

}

public void setContent(List content) {

this.content = content;

}

public Sort getSort() {

return sort;

}

public void setSort(Sort sort) {

this.sort = sort;

}

public PageImpl pageImpl() {

return new PageImpl(getContent(), new PageRequest(getNumber(),

getSize(), getSort()), getTotalElements());

}

}

然后修改您的代码以使用具体的类并获取PageImpl:

@SuppressWarnings("unchecked")

Page userPage = ((PageImplBean)new ObjectMapper().readValue(json, new TypeReference>() {})).pageImpl();

2020-09-18

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值