Skip to content

Commit

Permalink
bug fixed for Timestamp serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed Mar 28, 2020
1 parent 8276a40 commit 4f02ba3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void write(JSONSerializer serializer, Object object, Object fieldName, Ty
if (nanos > 0) {
buf = "0000-00-00 00:00:00.000000000".toCharArray();
int nanoSize = IOUtils.stringSize(nanos);
IOUtils.getChars(nanos, 30 - (9 - nanoSize), buf);
IOUtils.getChars(nanos, 29 - (9 - nanoSize), buf);
IOUtils.getChars(second, 19, buf);
IOUtils.getChars(minute, 16, buf);
IOUtils.getChars(hour, 13, buf);
Expand Down
15 changes: 8 additions & 7 deletions src/test/java/com/alibaba/json/bvt/issue_3000/Issue3093.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package com.alibaba.json.bvt.issue_3000;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.sql.Timestamp;
import java.util.Calendar;

public class Issue3093 extends TestCase {
public void test_for_issue() throws Exception {
String jsonStr = "{1:1}";
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
assertTrue(jsonObject.containsKey(1));
assertTrue(jsonObject.containsKey("1"));
assertEquals(1, jsonObject.get(1));
assertEquals(1, jsonObject.get("1"));
Timestamp ts = new Timestamp(Calendar.getInstance().getTimeInMillis());
String json = JSON.toJSONString(ts, SerializerFeature.UseISO8601DateFormat);
System.out.println(json);
}
}

0 comments on commit 4f02ba3

Please sign in to comment.