当前位置: 首页 > 知识库问答 >
问题:

无法反序列化STATT_OBJECT令牌外的java.util.ArrayList实例

仲孙德惠
2023-03-14
[{
        "id": 685509210310,
        "intention_id": 13042,
        "cuit": "133423122",
        "branch": "Local",
        "checkout": "7",
        "establishment_id": "21312",
        "transaction_datetime": "2021-03-10T17:07:10",
        "payment_method_id": 1,
        "payment_method_code": "VI",
        "payment_method_type": "credit_card",
        "card_data": {
            "card_brand": "Visa",
            "bin": "1211111",
            "last_four_digits": "0000",
            "bank_data": {
                "id": 1,
                "description": "Banco"
            }
        },
        "amount": 1200.00,
        "currency": "ARS",
        "installments": 1,
        "status": "approved",
        "status_details": {
            "card_authorization_code": "11111",
            "card_reference_number": " 00000",
            "response": {
                "type": "approved",
                "reason": {
                    "id": 0,
                    "description": "APROBADA (authno)",
                    "ticket_footer": "INFO ADICIONAL "
                }
            }
        },
        "terminal_data": {
            "trace_number": 43,
            "ticket_number": 121,
            "terminal_number": "87212121"
        }
    }
]

强制转换的方法是

Collection read = new ObjectMapper().readValue(new_salida, new TypeReference<Collection>() {});

共有1个答案

李捷
2023-03-14

我不认为它会像你想要的那样起作用

这是应该走的路

Collection<YourObject> read = new ObjectMapper().readValue(new_salida, YourObject[].class);

yourobject必须定义,以便它能够保存您期望的json的值

>  {
>       "id":685509210310,
>       "intention_id":13042,
>       "cuit":"133423122",
>       "branch":"Local",
>       "checkout":"7",
>       "establishment_id":"21312",
>       "transaction_datetime":"2021-03-10T17:07:10",
>       "payment_method_id":1,
>       "payment_method_code":"VI",
>       "payment_method_type":"credit_card",
>       "card_data":{
>          "card_brand":"Visa",
>          "bin":"1211111",
>          "last_four_digits":"0000",
>          "bank_data":{
>             "id":1,
>             "description":"Banco"
>          }
>       },
>       "amount":1200.00,
>       "currency":"ARS",
>       "installments":1,
>       "status":"approved",
>       "status_details":{
>          "card_authorization_code":"11111",
>          "card_reference_number":" 00000",
>          "response":{
>             "type":"approved",
>             "reason":{
>                "id":0,
>                "description":"APROBADA (authno)",
>                "ticket_footer":"INFO ADICIONAL "
>             }
>          }
>       },
>       "terminal_data":{
>          "trace_number":43,
>          "ticket_number":121,
>          "terminal_number":"87212121"
>       }    }
 类似资料: