json解码错误

pinkon5k  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(309)

我想找一个 Page<T> 通过使用sping boots webclients从另一个微服务中删除。我调用api并尝试反序列化返回的page对象。
问题:我做错了什么?如何修复此错误?如果您需要更多的课程信息,请随时询问,我会尽快提供!:)
错误信息(裁剪)(当我呼叫时)http://localhost:8081/账号/)

There was an unexpected error (type=Internal Server Error, status=500).
JSON decoding error: Missing type id when trying to resolve subtype of [simple type, class de.rwth.swc.lab.ws2021.daifu.dataservice.data.models.accounts.Account]: missing type id property 'type' (for POJO property 'content'); nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class de.rwth.swc.lab.ws2021.daifu.dataservice.data.models.accounts.Account]: missing type id property 'type' (for POJO property 'content') at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 226] (through reference chain: de.rwth.swc.lab.ws2021.daifu.businesslogic.data.models.CustomPageImpl["content"]->java.util.ArrayList[0])
org.springframework.core.codec.DecodingException: JSON decoding error: Missing type id when trying to resolve subtype of [simple type, class de.rwth.swc.lab.ws2021.daifu.dataservice.data.models.accounts.Account]: missing type id property 'type' (for POJO property 'content'); nested exception is com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class de.rwth.swc.lab.ws2021.daifu.dataservice.data.models.accounts.Account]: missing type id property 'type' (for POJO property 'content')
 at [Source: (io.netty.buffer.ByteBufInputStream); line: 1, column: 226] (through reference chain: de.rwth.swc.lab.ws2021.daifu.businesslogic.data.models.CustomPageImpl["content"]->java.util.ArrayList[0])
    at org.springframework.http.codec.json.AbstractJackson2Decoder.processException(AbstractJackson2Decoder.java:228)
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ⇢ Body from GET http://localhost:8080/api/v1/accounts [DefaultClientResponse]
Stack trace:
        at org.springframework.http.codec.json.AbstractJackson2Decoder.processException(AbstractJackson2Decoder.java:228)
        at org.springframework.http.codec.json.AbstractJackson2Decoder.decode(AbstractJackson2Decoder.java:186)
        at org.springframework.http.codec.json.AbstractJackson2Decoder.lambda$decodeToMono$1(AbstractJackson2Decoder.java:172)
        at reactor.core.publisher.MonoFlatMap$FlatMapMain.onNext(MonoFlatMap.java:125)
        at ........

当我调用http://localhost:8080/api/v1/帐户)

{
    "content": [
        {
            "id": 1,
            "accountNumber": 57041732,
            "balance": 11111.54,
            "overdraftInterest": 0.16,
            "overdraftLimit": 2000.0,
            "creditCards": [
                {
                    "id": 1,
                    "creditCardNumber": 1012728128,
                    "creditLine": 0.56,
                    "nextDebitingDay": "2020-12-24T23:00:00"
                }
            ]
        },
        {
            "id": 5,
            "accountNumber": 54586428,
            "balance": 5000.23,
            "overdraftInterest": 0.05,
            "overdraftLimit": 1000.0,
            "creditCards": []
        },
        {
            "id": 6,
            "accountNumber": 101026488,
            "balance": 5000.23,
            "overdraftInterest": 0.05,
            "overdraftLimit": 1000.0,
            "creditCards": []
        },
        {
            "id": 14,
            "accountNumber": 15578655,
            "balance": 12540.54,
            "overdraftInterest": 0.16,
            "overdraftLimit": 2000.0,
            "creditCards": [
                {
                    "id": 2,
                    "creditCardNumber": 444730208,
                    "creditLine": 0.56,
                    "nextDebitingDay": "2020-12-24T23:00:00"
                }
            ]
        }
    ],
    "pageable": {
        "sort": {
            "sorted": false,
            "unsorted": true,
            "empty": true
        },
        "offset": 0,
        "pageNumber": 0,
        "pageSize": 10,
        "unpaged": false,
        "paged": true
    },
    "last": true,
    "totalPages": 1,
    "totalElements": 4,
    "size": 10,
    "number": 0,
    "sort": {
        "sorted": false,
        "unsorted": true,
        "empty": true
    },
    "first": true,
    "numberOfElements": 4,
    "empty": false
}

函数,该函数调用api

public <T extends Account> List<T> getAllAccounts() {
    ParameterizedTypeReference<CustomPageImpl<T>> typeReference = new ParameterizedTypeReference<CustomPageImpl<T>>(){};
    CustomPageImpl<T> prodData = client.get().uri("/accounts").retrieve().bodyToMono(typeReference).block();

    return prodData.getContent();
}

custompageimpl(无导入)

@JsonIgnoreProperties(ignoreUnknown = true)
public class CustomPageImpl<T> extends PageImpl<T> {
    private static final long serialVersionUID = 1L;

    @JsonCreator(mode = JsonCreator.Mode.PROPERTIES)
    public CustomPageImpl(@JsonProperty("content") List<T> content,
            @JsonProperty("number") int number,
            @JsonProperty("size") int size,
            @JsonProperty("totalElements") Long totalElements) {
        super(content, PageRequest.of(number, size), totalElements);
    }
    public CustomPageImpl(List<T> content, Pageable pageable, long total) {
        super(content, pageable, total);
    }

    public CustomPageImpl(List<T> content) {
        super(content);
    }

    public CustomPageImpl() {
        super(new ArrayList<>());
    }
}

accountrepository(account实现这个)

public interface AccountRepository extends JpaRepository<Account, Integer>, CustomizedAccountRepository {
    Page<Account> findAllByCustomer_Id(Integer customerId, PageRequest pageRequest);
    Optional<Account> findByAccountNumber(int accountNumber);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题