diff --git a/CliArg/pom.xml b/CliArg/pom.xml index 1d005f9..6a72d51 100644 --- a/CliArg/pom.xml +++ b/CliArg/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml CliArg diff --git a/HiveUDF/pom.xml b/HiveUDF/pom.xml index 5769018..968c63d 100644 --- a/HiveUDF/pom.xml +++ b/HiveUDF/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml HiveUDF diff --git a/JSONCoder/pom.xml b/JSONCoder/pom.xml index 740c6cf..3e64c9b 100644 --- a/JSONCoder/pom.xml +++ b/JSONCoder/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml JSONCoder diff --git a/SnapshotTest/pom.xml b/SnapshotTest/pom.xml index de7893d..e296aeb 100644 --- a/SnapshotTest/pom.xml +++ b/SnapshotTest/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml SnapshotTest diff --git a/core/pom.xml b/core/pom.xml index 8cd3c0b..8aa7f22 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml core diff --git a/core/src/main/java/org/jsonex/core/util/BeanProperty.java b/core/src/main/java/org/jsonex/core/util/BeanProperty.java index c97a2ff..4653ec1 100644 --- a/core/src/main/java/org/jsonex/core/util/BeanProperty.java +++ b/core/src/main/java/org/jsonex/core/util/BeanProperty.java @@ -79,7 +79,7 @@ public Object get(Object obj){ return field.get(obj); } } catch(Exception e) { - throw new InvokeRuntimeException("error get value:" + name + ", class:" + obj.getClass(), e); + throw new InvokeRuntimeException("error get value:" + name + ", class:" + obj.getClass() + ";hasChecker:" + hasChecker, e); } throw new InvokeRuntimeException("field is not readable: " + name + ", class:" + obj.getClass()); } diff --git a/core/src/main/java/org/jsonex/core/util/ClassUtil.java b/core/src/main/java/org/jsonex/core/util/ClassUtil.java index 29c6fff..bf6b459 100644 --- a/core/src/main/java/org/jsonex/core/util/ClassUtil.java +++ b/core/src/main/java/org/jsonex/core/util/ClassUtil.java @@ -124,6 +124,11 @@ private static Map getPropertiesNoCache(Class cls) { case has: prop.hasChecker = m; break; case set: prop.setter = m; break; case is: + if (prop.getter == null) + prop.getter = m; + else + prop.hasChecker = m ; + break; case get: if (prop.getter == null) prop.getter = m; diff --git a/core/src/main/java/org/jsonex/core/util/LangUtil.java b/core/src/main/java/org/jsonex/core/util/LangUtil.java index 53b8a3a..53ccd18 100644 --- a/core/src/main/java/org/jsonex/core/util/LangUtil.java +++ b/core/src/main/java/org/jsonex/core/util/LangUtil.java @@ -3,6 +3,7 @@ import lombok.SneakyThrows; import org.jsonex.core.type.Nullable; +import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -124,4 +125,16 @@ public static T seq(Runnable action1, Runnable action2, T val) { action2.run(); return val; } + + /** + * Convert a block of code with local variables definitions into an single expression, it's useful to avoid code block + * in lambda statement. + */ + public static R with(T val, Function action) { + return action.apply(val); + } + + public static R with(T1 val1, T2 val2, BiFunction action) { + return action.apply(val1, val2); + } } diff --git a/core/src/test/java/org/jsonex/core/util/LangUtilTest.java b/core/src/test/java/org/jsonex/core/util/LangUtilTest.java index 3a28b04..588221e 100644 --- a/core/src/test/java/org/jsonex/core/util/LangUtilTest.java +++ b/core/src/test/java/org/jsonex/core/util/LangUtilTest.java @@ -65,4 +65,9 @@ static class C { assertEquals(val, LangUtil.seq(() -> i[0] += 1, () -> i[0] += 1, val)); assertEquals(3, i[0]); } + + @Test public void testWith() { + assertEquals("abcd", LangUtil.with("abc", a -> a + "d")); + assertEquals("abcd", LangUtil.with("abc", "d", (a, b) -> a + b)); + } } diff --git a/csv/pom.xml b/csv/pom.xml index 9de1ca0..cb39418 100644 --- a/csv/pom.xml +++ b/csv/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml csv diff --git a/pom.xml b/pom.xml index fa9f6ec..7c09e9d 100755 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.jsonex jcParent - 0.1.26 + 0.1.27 pom JSONCoder Parent JSONCoder Parent diff --git a/treedoc/pom.xml b/treedoc/pom.xml index 676f702..6a89f1f 100644 --- a/treedoc/pom.xml +++ b/treedoc/pom.xml @@ -6,7 +6,7 @@ org.jsonex jcParent - 0.1.26 + 0.1.27 ../pom.xml treedoc