码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-08-07 17:38:20      阅读:729      评论:0      收藏:0      [点我收藏+]

标签:stat   nts   nal   cep   异常   ack   status   sage   原因   

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 constructor

标签:stat   nts   nal   cep   异常   ack   status   sage   原因   

原文地址:https://www.cnblogs.com/passedbylove/p/11316538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!