287 Star 717 Fork 266

wenshao / fastjson

 / 详情

序列化泛型对象时,create asm serializer error, verson 1.2.54错误

Backlog
Opened this issue  
2018-12-27 17:50

create asm serializer error, verson 1.2.54错误,这个问题貌似你之前修复过,但现在还是这样,我使用了泛型包装类,在进行序列化的时候报错:

如下代码:
public class DeserializationTest {
public static void main(String[] args) {
ResultData<List<ResultData.Person>> resultData = new ResultData<>();

    List<ResultData.Person> list = new LinkedList<>();
    for(int i = 1; i <= 3; i++){
        ResultData.Person person = new ResultData.Person();
        person.setName("tom" + i);
        person.setAge(i * 2);
        person.setCreatedOn(new Date());
        list.add(person);
    }
    resultData.setData(list);
    resultData.setTotal(100);
    String result = JSON.toJSONString(resultData);
    System.out.println("系列化结果是:" + result);
}

}
其中,ResultData数据结构为:
public class ResultData {
private long total;
private T data;

public ResultData() {
}

public T getData() {
    return this.data;
}

public void setData(T data) {
    this.data = data;
}

public long getTotal() {
    return this.total;
}

public void setTotal(long total) {
    this.total = total;
}

/**
 * @author wangyafei05
 * @date 2018/12/27 17:10
 */
public static class Person {
    private String name;
    private Integer age;
    private Date createdOn;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }
}

}

报错信息:
Exception in thread "main" com.alibaba.fastjson.JSONException: create asm serializer error, verson 1.2.54, class class com.泛型测试.ResultData
at com.alibaba.fastjson.serializer.SerializeConfig.createJavaBeanSerializer(SerializeConfig.java:243)
at com.alibaba.fastjson.serializer.SerializeConfig.createJavaBeanSerializer(SerializeConfig.java:103)
at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:743)
at com.alibaba.fastjson.serializer.SerializeConfig.getObjectWriter(SerializeConfig.java:415)
at com.alibaba.fastjson.serializer.JSONSerializer.getObjectWriter(JSONSerializer.java:382)
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:278)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:676)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:614)
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:579)
at com.泛型测试.DeserializationTest.main(DeserializationTest.java:27)
Caused by: java.lang.UnsupportedOperationException
at com.alibaba.fastjson.asm.ByteVector.putUTF8(ByteVector.java:185)
at com.alibaba.fastjson.asm.ClassWriter.newUTF8(ClassWriter.java:272)
at com.alibaba.fastjson.asm.ClassWriter.newClassItem(ClassWriter.java:283)
at com.alibaba.fastjson.asm.ClassWriter.newConstItem(ClassWriter.java:262)
at com.alibaba.fastjson.asm.MethodWriter.visitLdcInsn(MethodWriter.java:217)
at com.alibaba.fastjson.serializer.ASMSerializerFactory.createJavaBeanSerializer(ASMSerializerFactory.java:199)
at com.alibaba.fastjson.serializer.SerializeConfig.createASMSerializer(SerializeConfig.java:81)
at com.alibaba.fastjson.serializer.SerializeConfig.createJavaBeanSerializer(SerializeConfig.java:227)
... 9 more

Comments (4)

追风者 createdtask

我也遇到了,嵌套的泛型序列化后,嵌套的泛型变成JSONObject了,没有变成TypeRefrence的泛型

包名含有中文的原因

@hulak 是的解决问题了

Sign in to comment

Status
Assignees
Milestones
Pull Requests
Successfully merging a pull request will close this issue.
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(5)
1464254 timvanx 1578952130 112593 caohenghui 1578918069
Java
1
https://git.oschina.net/wenshao/fastjson.git
git@git.oschina.net:wenshao/fastjson.git
wenshao
fastjson
fastjson

Search