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

fix LocalDate use millis as default DateFormat, for issue #2477 Monster Yesterday 23:19 #2495

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class JSON
features |= SerializerFeature.SkipTransientField.getMask();
features |= SerializerFeature.WriteEnumUsingName.getMask();
features |= SerializerFeature.SortField.getMask();

features |= SerializerFeature.UseISO8601DateFormat.getMask();
DEFAULT_GENERATE_FEATURE = features;
}

Expand Down Expand Up @@ -1628,7 +1628,7 @@ public static byte[] toJSONBytes(Object object, int defaultFeatures, SerializerF
}

public static byte[] toJSONBytes(Object object, SerializeFilter filter) {
return toJSONBytes(object, SerializeConfig.global, new SerializeFilter[] {filter}, DEFAULT_GENERATE_FEATURE);
return toJSONBytes(object, SerializeConfig.global, new SerializeFilter[]{filter}, DEFAULT_GENERATE_FEATURE);
}

public static byte[] toJSONBytes(Object object, SerializeFilter filter, SerializerFeature... features) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.alibaba.fastjson.issue_2400;

import com.alibaba.fastjson.JSON;
import org.junit.jupiter.api.Test;

import java.time.*;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Issue2477 {
@Test
public void test_for_issue() {
Map<String, Object> map = new HashMap<>();
map.put("localDate", LocalDate.now());
map.put("date", Date.from(Instant.now()));
map.put("instant", Instant.now());
map.put("localDateTime", LocalDateTime.now());
map.put("localTime", LocalTime.now());
map.put("offsetDateTime", OffsetDateTime.now());
map.put("zonedDateTime", ZonedDateTime.now());
map.put("calendar", Calendar.getInstance());
System.out.println(JSON.toJSONString(map));
}
}