fastjson2将bean转String失败,同样的bean换成fastjson则转String正常

ztyzrc3y  于 2022-12-31  发布在  其他
关注(0)|答案(3)|浏览(331)

报错:java.lang.UnsupportedOperationException: can't load this type of class file

wgx48brx

wgx48brx1#

能否提供重现问题的testcase?

o0lyfsai

o0lyfsai2#

public class AiResultBean {
@JSONField()
private String code;
@JSONField(ordinal = 1)
private String message;
@JSONField(ordinal = 2)
private List data;

public void setCode(String code) {
    this.code = code;
}

public String getCode() {
    return code;
}

public void setMessage(String message) {
    this.message = message;
}

public String getMessage() {
    return message;
}

public void setData(List<Data> data) {
    this.data = data;
}

public List<Data> getData() {
    return data;
}

public static class Data {
    private String label;
    private double confidence;
    private int xmin;
    private int xmax;
    private int ymin;
    private int ymax;

    public void setLabel(String label) {
        this.label = label;
    }

    public String getLabel() {
        return label;
    }

    public void setConfidence(double confidence) {
        this.confidence = confidence;
    }

    public double getConfidence() {
        return confidence;
    }

    public void setXmin(int xmin) {
        this.xmin = xmin;
    }

    public int getXmin() {
        return xmin;
    }

    public void setXmax(int xmax) {
        this.xmax = xmax;
    }

    public int getXmax() {
        return xmax;
    }

    public void setYmin(int ymin) {
        this.ymin = ymin;
    }

    public int getYmin() {
        return ymin;
    }

    public void setYmax(int ymax) {
        this.ymax = ymax;
    }

    public int getYmax() {
        return ymax;
    }
}

}

AiResultBean aiResultBean = new AiResultBean();
aiResultBean.setCode("0");
aiResultBean.setMessage("Success");
List<AiResultBean.Data> dataList = new ArrayList<>();
AiResultBean.Data dataItem = new AiResultBean.Data();
dataItem.setLabel("DaoXianYiWu");
dataItem.setConfidence(0.5646306276321411);
dataItem.setXmin(1024);
dataItem.setYmin(1280);
dataItem.setXmax(1536);
dataItem.setYmax(1920);
dataList.add(dataItem);
AiResultBean.Data dataItem1 = new AiResultBean.Data();
dataItem1.setLabel("DaoXianYiWu");
dataItem1.setConfidence(0.6646306276321411);
dataItem1.setXmin(1025);
dataItem1.setYmin(1281);
dataItem1.setXmax(1537);
dataItem1.setYmax(1921);
dataList.add(dataItem1);
AiResultBean.Data dataItem2 = new AiResultBean.Data();
dataItem2.setLabel("DaoXianYiWu");
dataItem2.setConfidence(0.7646306276321411);
dataItem2.setXmin(1026);
dataItem2.setYmin(1282);
dataItem2.setXmax(1538);
dataItem2.setYmax(1922);
dataList.add(dataItem2);
aiResultBean.setData(dataList);
Log.d(TAG, "onCreate: ai fastjson2 = " + JSON.toJSONString(aiResultBean));

tf7tbtn2

tf7tbtn23#

bean的代码github显示有bug,
@JSONField(ordinal = 2)
private List data;
无法显示List后面的类型

相关问题