This commit is contained in:
Looly
2022-01-15 19:22:40 +08:00
parent 4b44716b5f
commit 749c0f8727
6 changed files with 64 additions and 4 deletions

View File

@@ -671,7 +671,6 @@ public class JSONObject implements JSON, JSONGetter<String>, Map<String, Object>
// 不支持对象类型转换为JSONObject
throw new JSONException("Unsupported type [{}] to JSONObject!", source.getClass());
}
}
/**

View 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;
}
}

View File

@@ -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;