mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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>>>() {
|
||||
});
|
||||
|
Reference in New Issue
Block a user