mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
4e8060e441
commit
fe6c48f08d
@ -114,7 +114,9 @@ public class TemporalAccessorUtil extends TemporalUtil{
|
||||
|
||||
/**
|
||||
* {@link TemporalAccessor}转换为 时间戳(从1970-01-01T00:00:00Z开始的毫秒数)<br>
|
||||
* 如果为{@link Month},调用{@link Month#getValue()}
|
||||
* 如果为{@link Month},调用{@link Month#getValue()}<br>
|
||||
* 如果为{@link DayOfWeek},调用{@link DayOfWeek#getValue()}<br>
|
||||
* 如果为{@link Era},调用{@link Era#getValue()}
|
||||
*
|
||||
* @param temporalAccessor Date对象
|
||||
* @return {@link Instant}对象
|
||||
@ -123,6 +125,10 @@ public class TemporalAccessorUtil extends TemporalUtil{
|
||||
public static long toEpochMilli(final TemporalAccessor temporalAccessor) {
|
||||
if(temporalAccessor instanceof Month){
|
||||
return ((Month) temporalAccessor).getValue();
|
||||
} else if(temporalAccessor instanceof DayOfWeek){
|
||||
return ((DayOfWeek) temporalAccessor).getValue();
|
||||
} else if(temporalAccessor instanceof Era){
|
||||
return ((Era) temporalAccessor).getValue();
|
||||
}
|
||||
return toInstant(temporalAccessor).toEpochMilli();
|
||||
}
|
||||
|
@ -16,9 +16,7 @@ import cn.hutool.json.JSONException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.MonthDay;
|
||||
import java.time.chrono.Era;
|
||||
import java.time.temporal.TemporalAccessor;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
@ -139,8 +137,7 @@ public class JSONWriter extends Writer {
|
||||
*/
|
||||
@SuppressWarnings({"UnusedReturnValue", "resource"})
|
||||
public JSONWriter writeField(final MutableEntry<Object, Object> pair, final Predicate<MutableEntry<Object, Object>> predicate) {
|
||||
final Object value = pair.getValue();
|
||||
if (null == value && config.isIgnoreNullValue()) {
|
||||
if (null == pair.getValue() && config.isIgnoreNullValue()) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -151,13 +148,12 @@ public class JSONWriter extends Writer {
|
||||
}
|
||||
}
|
||||
|
||||
final Object key = pair.getKey();
|
||||
if(false == arrayMode){
|
||||
// JSONObject模式,写出键,否则只输出值
|
||||
writeKey(StrUtil.toString(key));
|
||||
writeKey(StrUtil.toString(pair.getKey()));
|
||||
}
|
||||
|
||||
return writeValueDirect(value, predicate);
|
||||
return writeValueDirect(pair.getValue(), predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -241,11 +237,9 @@ public class JSONWriter extends Writer {
|
||||
writeNumberValue((Number) value);
|
||||
} else if (value instanceof Date || value instanceof Calendar || value instanceof TemporalAccessor) {
|
||||
// issue#2572@Github
|
||||
if(value instanceof TemporalAccessor){
|
||||
if(value instanceof DayOfWeek || value instanceof java.time.Month || value instanceof Era || value instanceof MonthDay){
|
||||
writeQuoteStrValue(value.toString());
|
||||
return this;
|
||||
}
|
||||
if(value instanceof MonthDay){
|
||||
writeQuoteStrValue(value.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
final String format = (null == config) ? null : config.getDateFormat();
|
||||
|
@ -18,7 +18,7 @@ public class Issue2572Test {
|
||||
weeks.add(DayOfWeek.MONDAY);
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("weeks", weeks);
|
||||
Assert.assertEquals("{\"weeks\":[\"MONDAY\"]}", obj.toString());
|
||||
Assert.assertEquals("{\"weeks\":[1]}", obj.toString());
|
||||
|
||||
final Map<String, Set<DayOfWeek>> monthDays1 = obj.toBean(new TypeReference<Map<String, Set<DayOfWeek>>>() {
|
||||
});
|
||||
@ -31,7 +31,7 @@ public class Issue2572Test {
|
||||
months.add(Month.DECEMBER);
|
||||
final JSONObject obj = new JSONObject();
|
||||
obj.set("months", months);
|
||||
Assert.assertEquals("{\"months\":[\"DECEMBER\"]}", obj.toString());
|
||||
Assert.assertEquals("{\"months\":[12]}", obj.toString());
|
||||
|
||||
final Map<String, Set<Month>> monthDays1 = obj.toBean(new TypeReference<Map<String, Set<Month>>>() {
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user