Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date类型序列化后转回去时出错(2.0.44还是不行) #2086

Closed
wghdir opened this issue Dec 8, 2023 · 4 comments
Closed

Date类型序列化后转回去时出错(2.0.44还是不行) #2086

wghdir opened this issue Dec 8, 2023 · 4 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@wghdir
Copy link

wghdir commented Dec 8, 2023

RedisFastJsonWraper:
public class RedisFastJsonWraper<T> {
    private T value;

    public RedisFastJsonWraper() {
    }

    public RedisFastJsonWraper(T value) {
        this.value = value;
    }

    public T getValue() {
        return value;
    }

    public void setValue(T value) {
        this.value = value;
    }
}
//测试的demo
    public static void main(String[] args) {
        Map<String,Object> map = new HashMap<>();
        map.put("mydate",new Date());
        map.put("wgh",1);
        map.put("age",21);
        RedisFastJsonWraper<Map> wraperSet = new RedisFastJsonWraper<>(map);
        String msg = JSON.toJSONString(wraperSet, SerializerFeature.WriteClassName);
        System.out.println(msg);
        JSONObject.parseObject(msg);
    }
//控制台输出
{"@type":"com.redis.serializer.RedisFastJsonWraper","value":{"@type":"java.util.HashMap","mydate":new Date(1702017744851),"wgh":1,"age":21}}
Exception in thread "main" com.alibaba.fastjson.JSONException: json syntax error, not match null, offset 99
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:198)
	at com.redis.serializer.RedisSerializer.main(RedisSerializer.java:22)
Caused by: com.alibaba.fastjson2.JSONException: json syntax error, not match null, offset 99
	at com.alibaba.fastjson2.JSONReaderUTF16.readNull(JSONReaderUTF16.java:5094)
	at com.alibaba.fastjson2.JSONReader.readObject(JSONReader.java:2349)
	at com.alibaba.fastjson2.JSONReader.read(JSONReader.java:2147)
	at com.alibaba.fastjson.JSON.parseObject(JSON.java:189)
@wghdir wghdir added the bug Something isn't working label Dec 8, 2023
@wghdir
Copy link
Author

wghdir commented Dec 8, 2023

用的是1.x 兼容版本

@wenshao wenshao added this to the 2.0.44 milestone Dec 24, 2023
@wenshao wenshao added the fixed label Dec 24, 2023
@wenshao
Copy link
Member

wenshao commented Dec 24, 2023

@wenshao wenshao closed this as completed Dec 24, 2023
@wghdir
Copy link
Author

wghdir commented Dec 26, 2023

还是不行,有错误提示,是那个 new Date()通过不了,代码里认为是null了
image
我想可能是这个地方没有处理到,有的地方是处理了的
image
麻烦下一个更新修正一下。

java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:760)
at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:747)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:745)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1290)
at com.example.nativedemo.NativedemoApplication.main(NativedemoApplication.java:30)
Caused by: com.alibaba.fastjson.JSONException: json syntax error, not match null114
at com.alibaba.fastjson.JSON.parseObject(JSON.java:524)
at com.example.nativedemo.RunAfterBoot.dateError(RunAfterBoot.java:92)
at com.example.nativedemo.RunAfterBoot.run(RunAfterBoot.java:80)
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:757)
... 14 common frames omitted
Caused by: com.alibaba.fastjson2.JSONException: json syntax error, not match null114
at com.alibaba.fastjson2.JSONReaderUTF8.readNull(JSONReaderUTF8.java:6970)
at com.alibaba.fastjson2.reader.ObjectReaderImplObject.readObject(ObjectReaderImplObject.java:219)
at com.alibaba.fastjson2.reader.ORG_1_1_RedisFastJsonWraper.readObject(Unknown Source)
at com.alibaba.fastjson.JSON.parseObject(JSON.java:514)
... 17 common frames omitted

Process finished with exit code 1

@wenshao wenshao modified the milestones: 2.0.44, 2.0.45 Dec 26, 2023
@wenshao wenshao removed the fixed label Dec 26, 2023
@wghdir wghdir changed the title Date类型序列化后转回去时出错 Date类型序列化后转回去时出错(2.0.44还是不行) Dec 26, 2023
@wenshao wenshao reopened this Jan 7, 2024
@wenshao wenshao modified the milestones: 2.0.45, 2.0.46 Jan 7, 2024
@wenshao wenshao added the fixed label Jan 27, 2024
@wenshao
Copy link
Member

wenshao commented Jan 29, 2024

https://github.com/alibaba/fastjson2/releases/tag/2.0.46
问题已修复,请用新版本

@wenshao wenshao closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

No branches or pull requests

2 participants