-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG]2.0.14定制java.sql.Date, java.sql.Time, java.util.Date序列化格式失效 #781
Comments
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.15-SNAPSHOT/ 你也可以用一下的代码,更简洁: @Test
public void test1() {
JSON.mixIn(Date.class, DateMixin.class);
long millis = 1663595616049L;
Bean1 t = new Bean1();
t.setDate(new Date(millis));
String s = JSON.toJSONString(t);
assertEquals("{\"date\":1663595616049}", s);
}
@JSONType(format = "millis")
public static class DateMixin {
}
static class Bean1 {
Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
} |
@wenshao java.util.Date仍然没有显示时间戳 import java.lang.reflect.Type;
import java.util.Date;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.alibaba.fastjson2.writer.ObjectWriter;
import cn.nextop.gadget.core.util.Objects;
/**
* @author Baoyi Chen
*/
public class Main {
public static void main(String[] args) {
JSON.register(java.util.Date.class, new ObjectWriter<java.util.Date>() {
@Override
public void write(JSONWriter jsonWriter, Object object, Object fieldName, Type fieldType, long features) {
Date v = Objects.cast(object);
jsonWriter.writeString(String.valueOf(v.getTime()));
}
});
Test t = new Test();
t.setDate(new Date(System.currentTimeMillis()));
String s = JSON.toJSONString(t);
System.out.println(s);
}
static class Test {
java.util.Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
} |
@wenshao 麻烦看下上面的消息 |
wenshao
added a commit
that referenced
this issue
Oct 5, 2022
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
问题描述
简要描述您碰到的问题。
环境信息
请填写以下信息:
重现步骤
如何操作可以重现该问题:
输出
期待输出
java.sql.Time,java.util.Date也是如此
The text was updated successfully, but these errors were encountered: