Merge branch 'apache-master' into 2.7.18-release
This commit is contained in:
commit
fddf601b2b
|
|
@ -22,6 +22,7 @@ import java.math.BigInteger;
|
|||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
|
|
@ -33,6 +34,11 @@ public class CompatibleTypeUtils {
|
|||
|
||||
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
/**
|
||||
* the text to parse such as "2007-12-03T10:15:30"
|
||||
*/
|
||||
private static final int ISO_LOCAL_DATE_TIME_MIN_LEN = 19;
|
||||
|
||||
private CompatibleTypeUtils() {
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +133,12 @@ public class CompatibleTypeUtils {
|
|||
if (StringUtils.isEmpty(string)) {
|
||||
return null;
|
||||
}
|
||||
return LocalDateTime.parse(string).toLocalTime();
|
||||
|
||||
if (string.length() >= ISO_LOCAL_DATE_TIME_MIN_LEN) {
|
||||
return LocalDateTime.parse(string).toLocalTime();
|
||||
} else {
|
||||
return LocalTime.parse(string);
|
||||
}
|
||||
}
|
||||
if (type == Class.class) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ import java.lang.reflect.Proxy;
|
|||
import java.lang.reflect.Type;
|
||||
import java.lang.reflect.TypeVariable;
|
||||
import java.lang.reflect.WildcardType;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
|
@ -134,6 +137,10 @@ public class PojoUtils {
|
|||
if (ReflectUtils.isPrimitives(pojo.getClass())) {
|
||||
return pojo;
|
||||
}
|
||||
|
||||
if (pojo instanceof LocalDate || pojo instanceof LocalDateTime || pojo instanceof LocalTime) {
|
||||
return pojo.toString();
|
||||
}
|
||||
|
||||
if (pojo instanceof Class) {
|
||||
return ((Class) pojo).getName();
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ import org.junit.jupiter.api.Test;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
|
@ -792,6 +795,22 @@ public class PojoUtilsTest {
|
|||
assertEquals(parent.getFeatures().get("height"), "177cm");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJava8Time() {
|
||||
|
||||
Object localDateTimeGen = PojoUtils.generalize(LocalDateTime.now());
|
||||
Object localDateTime = PojoUtils.realize(localDateTimeGen, LocalDateTime.class);
|
||||
assertEquals(localDateTimeGen, localDateTime.toString());
|
||||
|
||||
Object localDateGen = PojoUtils.generalize(LocalDate.now());
|
||||
Object localDate = PojoUtils.realize(localDateGen, LocalDate.class);
|
||||
assertEquals(localDateGen, localDate.toString());
|
||||
|
||||
Object localTimeGen = PojoUtils.generalize(LocalTime.now());
|
||||
Object localTime = PojoUtils.realize(localTimeGen, LocalTime.class);
|
||||
assertEquals(localTimeGen, localTime.toString());
|
||||
}
|
||||
|
||||
public enum Day {
|
||||
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue