jack放序列化自定义字段绑定,报错:can only instantiate non-static inner class by using default, no-argument constru

Posted passedbylove

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jack放序列化自定义字段绑定,报错:can only instantiate non-static inner class by using default, no-argument constru相关的知识,希望对你有一定的参考价值。

package com.xxx;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

public class TestJsonNode 

    @Test
    public void test()
    
        String json = "\"status\": 0, \"segment\": 0, \"result\": \"hypotheses\": [\"transcript\": \"原 的 \"], \"final\": false, \"id\": \"ba040ef0-9134-46f3-8a95-cc9b70868c07\"";
        ObjectMapper objectMapper = new ObjectMapper();
        try 
//            JsonNode node = objectMapper.readTree(json);
//            boolean containsStatusField = node.has("status");
//            if(!containsStatusField)
//            
//                System.out.println("服务器异常");
//            
//
//            int status = node.findValue("status").intValue();
            //System.out.println(status);

            ASRConversionResponse response = objectMapper.readValue(json, ASRConversionResponse.class);

            System.out.println(response);

         catch (IOException e) 
            e.printStackTrace();
        
    

@Data
@NoArgsConstructor
public class ASRConversionResponse

    private Integer status;
    private String message;

    private List<Result> result;

    @JsonProperty("segment_start") //此处为自定义字段绑定类型
    private Float segmentStart;

    @JsonProperty("segment_length")
    private Float segmentLength;

    @JsonProperty("total_length")
    private Float totalLength;

    private short segment;

    private String id;



@Data
@NoArgsConstructor
  class Result

    @JsonProperty("final")
    private Boolean _final;

    private List<Hypotheses> hypotheses;


@Data
@NoArgsConstructor
  class Hypotheses

    private Float likelihood;
    private String transcript;


出错原因:把ASRConversionResponse内部类提出来,单独新建一个类ASRConversionResponse.java

以上是关于jack放序列化自定义字段绑定,报错:can only instantiate non-static inner class by using default, no-argument constru的主要内容,如果未能解决你的问题,请参考以下文章

keras 中带有 train_on_batch 的自定义 Loss fnc 用于重放学习

jquery的自定义事件通过on绑定trigger触发

Vue2 已定义已绑定的Element表单数据对象报错 not defined on the instance but referenced during render.

Vue2 已定义已绑定的Element表单数据对象报错 not defined on the instance but referenced during render.

Vue组件绑定自定义事件

jQuery on() 方法 为选定已存在元素和未来元素绑定标准事件和自定义事件