mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix bug
This commit is contained in:
@@ -671,7 +671,6 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
|
||||
// 不支持对象类型转换为JSONObject
|
||||
throw new JSONException("Unsupported type [{}] to JSONObject!", source.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
43
hutool-json/src/test/java/cn/hutool/json/Issue2090Test.java
Executable file
43
hutool-json/src/test/java/cn/hutool/json/Issue2090Test.java
Executable file
@@ -0,0 +1,43 @@
|
||||
package cn.hutool.json;
|
||||
|
||||
import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
|
||||
/**
|
||||
* https://github.com/dromara/hutool/issues/2090
|
||||
*/
|
||||
public class Issue2090Test {
|
||||
|
||||
@Test
|
||||
public void parseTest(){
|
||||
final TestBean test = new TestBean();
|
||||
test.setLocalDate(LocalDate.now());
|
||||
|
||||
final JSONObject json = JSONUtil.parseObj(test);
|
||||
final TestBean test1 = json.toBean(TestBean.class);
|
||||
Assert.assertEquals(test, test1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLocalDateTest(){
|
||||
LocalDate localDate = LocalDate.now();
|
||||
final JSONObject jsonObject = JSONUtil.parseObj(localDate);
|
||||
Assert.assertNotNull(jsonObject.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void monthTest(){
|
||||
final JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.set("month", Month.JANUARY);
|
||||
Assert.assertEquals("{\"month\":1}", jsonObject.toString());
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TestBean{
|
||||
private LocalDate localDate;
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
Reference in New Issue
Block a user