You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@polygene.apache.org by ni...@apache.org on 2016/08/19 12:18:56 UTC
[22/25] zest-java git commit: ZEST-158 : Removed support for legacy
Map serialization format.
ZEST-158 : Removed support for legacy Map serialization format.
Project: http://git-wip-us.apache.org/repos/asf/zest-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/zest-java/commit/65c7df37
Tree: http://git-wip-us.apache.org/repos/asf/zest-java/tree/65c7df37
Diff: http://git-wip-us.apache.org/repos/asf/zest-java/diff/65c7df37
Branch: refs/heads/ValueSerializationCleaning
Commit: 65c7df37108e7d94a432aefc34d9aca020f64baf
Parents: 93b6d03
Author: Niclas Hedhman <ni...@hedhman.org>
Authored: Thu Jun 16 14:02:05 2016 +0800
Committer: Niclas Hedhman <ni...@hedhman.org>
Committed: Thu Jun 16 14:02:05 2016 +0800
----------------------------------------------------------------------
.../zest/api/property/IllegalTypeException.java | 77 ++++++++++
.../java/org/apache/zest/api/type/MapType.java | 17 ---
.../org/apache/zest/api/type/Serialization.java | 62 --------
.../apache/zest/api/value/ValueSerializer.java | 12 --
.../runtime/composite/CompositeMethodModel.java | 31 +++-
.../zest/runtime/property/PropertyModel.java | 28 ++--
.../zest/runtime/types/ValueTypeFactory.java | 20 ++-
.../apache/zest/bootstrap/InvalidTypesTest.java | 141 +++++++++++++++++++
.../spi/value/ValueDeserializerAdapter.java | 44 ++----
.../zest/spi/value/ValueSerializerAdapter.java | 50 ++-----
.../orgjson/OrgJsonValueDeserializer.java | 37 -----
.../jackson/JacksonValueDeserializer.java | 35 -----
.../stax/StaxValueDeserializer.java | 29 ----
.../serialization/JsonRepresentation.java | 2 +-
14 files changed, 288 insertions(+), 297 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/api/src/main/java/org/apache/zest/api/property/IllegalTypeException.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/property/IllegalTypeException.java b/core/api/src/main/java/org/apache/zest/api/property/IllegalTypeException.java
new file mode 100644
index 0000000..cf811a1
--- /dev/null
+++ b/core/api/src/main/java/org/apache/zest/api/property/IllegalTypeException.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ */
+
+package org.apache.zest.api.property;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+/**
+ * Some known types are prohibited from use in Apache Zest.
+ *
+ * This exception is thrown when you try to use any of the prohibited types.
+ * The types are;
+ * <ul>
+ * <li>java.util.Date</li>
+ * <li>java.util.Calendar</li>
+ * <li>java.util.DateFormatter</li>
+ * <li>java.util.SimpleDateFormatter</li>
+ * <li>java.sql.Date</li>
+ * <li>java.sql.Time</li>
+ * <li>org.joda.time.*</li>
+ * </ul>
+ *
+ * This exception may be thrown either when a Property type is declared with any
+ * of these, or if a method under Zest control is called containing any of these
+ * types.
+ *
+ * If the system property zest.types.allow.prohibited=true, then the check is disabled
+ * and those types are allowed. Use with extreme care.
+ */
+public class IllegalTypeException extends RuntimeException
+{
+ public IllegalTypeException( String message )
+ {
+ super( message );
+ }
+
+
+ public static boolean checkProhibited( Type type )
+ {
+ if( type instanceof ParameterizedType )
+ {
+ // raw type is the container, e.g. Collection in Collection<String>
+ type = ( (ParameterizedType) type ).getRawType();
+ }
+ if( type instanceof Class )
+ {
+ String typeName = ( (Class) type ).getName();
+ return typeName.equals( "java.util.Date" )
+ || typeName.equals( "java.util.Calendar" )
+ || typeName.equals( "java.text.DateFormat" )
+ || typeName.equals( "java.text.SimpleDateFormat" )
+ || typeName.equals( "java.sql.Date" )
+ || typeName.equals( "java.sql.Time" )
+ || typeName.startsWith( "org.joda.time." );
+ }
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/api/src/main/java/org/apache/zest/api/type/MapType.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/type/MapType.java b/core/api/src/main/java/org/apache/zest/api/type/MapType.java
index 2fc6893..c76fd60 100644
--- a/core/api/src/main/java/org/apache/zest/api/type/MapType.java
+++ b/core/api/src/main/java/org/apache/zest/api/type/MapType.java
@@ -33,7 +33,6 @@ public final class MapType
private ValueType keyType;
private ValueType valueType;
- private final Serialization.Variant variant;
public static boolean isMap( Type type )
{
@@ -46,22 +45,11 @@ public final class MapType
return new MapType( Map.class, ValueType.of( keyType ), ValueType.of( valueType ) );
}
- public static MapType of( Class<?> keyType, Class<?> valueType, Serialization.Variant variant )
- {
- return new MapType( Map.class, ValueType.of( keyType ), ValueType.of( valueType ), variant );
- }
-
public MapType( Class<?> type, ValueType keyType, ValueType valueType )
{
- this( type, keyType, valueType, Serialization.Variant.entry );
- }
-
- public MapType( Class<?> type, ValueType keyType, ValueType valueType, Serialization.Variant variant )
- {
super( type );
this.keyType = keyType;
this.valueType = valueType;
- this.variant = variant;
if( !isMap( type ) )
{
throw new IllegalArgumentException( type + " is not a Map." );
@@ -78,11 +66,6 @@ public final class MapType
return valueType;
}
- public Serialization.Variant variant()
- {
- return variant;
- }
-
@Override
public String toString()
{
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/api/src/main/java/org/apache/zest/api/type/Serialization.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/type/Serialization.java b/core/api/src/main/java/org/apache/zest/api/type/Serialization.java
deleted file mode 100644
index 81a0188..0000000
--- a/core/api/src/main/java/org/apache/zest/api/type/Serialization.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- *
- */
-package org.apache.zest.api.type;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * Serialization options for Property intstances.
- * <p>
- * The {@code entry} type represents the explicit key=keyValue, value=valueValue. For JSON serialization;
- * </p>
- * <pre>
- * [
- * { "key1" : "value1" },
- * { "key2" : "value2" }
- * ]
- * </pre>
- * <p>
- * For XML serialization;
- * </p>
- * <pre>
- * <object>
- * <
- * </object>
- * </pre>
- * <p>
- * The {@code object} type represents the explicit keyValue=valueValue.
- * </p>
- */
-@Retention( RetentionPolicy.RUNTIME )
-@Target( { ElementType.TYPE, ElementType.METHOD } )
-@Documented
-public @interface Serialization
-{
- Variant value();
-
- enum Variant
- {
- entry, object
- }
-}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/api/src/main/java/org/apache/zest/api/value/ValueSerializer.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/zest/api/value/ValueSerializer.java b/core/api/src/main/java/org/apache/zest/api/value/ValueSerializer.java
index 6ab536e..249b78f 100644
--- a/core/api/src/main/java/org/apache/zest/api/value/ValueSerializer.java
+++ b/core/api/src/main/java/org/apache/zest/api/value/ValueSerializer.java
@@ -178,7 +178,6 @@ public interface ValueSerializer
* Default to TRUE.
*/
public static final String INCLUDE_TYPE_INFO = "includeTypeInfo";
- public static final String MAP_ENTRIES_AS_OBJECTS = "mapentriesasobjects";
private final Map<String, String> options = new HashMap<>();
/**
@@ -187,7 +186,6 @@ public interface ValueSerializer
public Options()
{
this.options.put( INCLUDE_TYPE_INFO, "true" );
- this.options.put( MAP_ENTRIES_AS_OBJECTS, "true" );
}
/**
@@ -208,16 +206,6 @@ public interface ValueSerializer
return put( INCLUDE_TYPE_INFO, false );
}
- public Options withMapEntriesAsObjects()
- {
- return put( MAP_ENTRIES_AS_OBJECTS, true );
- }
-
- public Options withMapEntriesAsKeyValuePairs()
- {
- return put( MAP_ENTRIES_AS_OBJECTS, false );
- }
-
/**
* Get Boolean option value.
* @param option The option
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
index 237b023..03d8868 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/composite/CompositeMethodModel.java
@@ -28,17 +28,20 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.zest.api.common.ConstructionException;
import org.apache.zest.api.composite.MethodDescriptor;
+import org.apache.zest.api.property.IllegalTypeException;
import org.apache.zest.api.structure.ModuleDescriptor;
import org.apache.zest.api.util.NullArgumentException;
import org.apache.zest.functional.HierarchicalVisitor;
import org.apache.zest.functional.VisitableHierarchy;
import org.apache.zest.runtime.injection.Dependencies;
import org.apache.zest.runtime.injection.DependencyModel;
-import org.apache.zest.spi.module.ModuleSpi;
+
+import static org.apache.zest.api.property.IllegalTypeException.checkProhibited;
/**
* JAVADOC
@@ -67,6 +70,7 @@ public final class CompositeMethodModel
MixinsModel mixinsModel
)
{
+ validateMethod( method );
this.method = method;
mixins = mixinsModel;
concerns = concernsModel;
@@ -83,6 +87,20 @@ public final class CompositeMethodModel
// instancePool = new SynchronizedCompositeMethodInstancePool();
}
+ private void validateMethod( Method method )
+ {
+ Class<?>[] parameterTypes = method.getParameterTypes();
+ for( Class type : parameterTypes )
+ {
+ if( checkProhibited( type ) )
+ {
+ throw new IllegalTypeException( "In method " + method.getName() + " of " + mixins + " has a argument type " + type
+ .getName() + ". This is a prohibited type in Apache Zest." );
+ }
+ }
+ }
+
+
// Model
@Override
@@ -100,7 +118,16 @@ public final class CompositeMethodModel
@SuppressWarnings( "unchecked" )
public Stream<DependencyModel> dependencies()
{
- return Stream.of( concerns, sideEffects ).filter( e -> e != null ).flatMap( Dependencies::dependencies );
+ return Stream.of( concerns, sideEffects )
+ .filter( e -> e != null )
+ .flatMap( new Function<Dependencies, Stream<DependencyModel>>()
+ {
+ @Override
+ public Stream<DependencyModel> apply( Dependencies dependencies )
+ {
+ return dependencies.dependencies();
+ }
+ } );
// return flattenIterables( filter( notNull(), iterable( concerns != null ? concerns.dependencies() : null,
// sideEffects != null ? sideEffects.dependencies() : null ) ) );
}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java b/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
index 807194f..c140850 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/property/PropertyModel.java
@@ -35,12 +35,12 @@ import org.apache.zest.api.constraint.ConstraintViolationException;
import org.apache.zest.api.entity.Queryable;
import org.apache.zest.api.property.DefaultValues;
import org.apache.zest.api.property.GenericPropertyInfo;
+import org.apache.zest.api.property.IllegalTypeException;
import org.apache.zest.api.property.InvalidPropertyTypeException;
import org.apache.zest.api.property.Property;
import org.apache.zest.api.property.PropertyDescriptor;
import org.apache.zest.api.service.NoSuchServiceException;
import org.apache.zest.api.structure.ModuleDescriptor;
-import org.apache.zest.api.type.Serialization;
import org.apache.zest.api.type.ValueCompositeType;
import org.apache.zest.api.type.ValueType;
import org.apache.zest.api.util.Classes;
@@ -54,6 +54,8 @@ import org.apache.zest.runtime.model.Binder;
import org.apache.zest.runtime.model.Resolution;
import org.apache.zest.runtime.types.ValueTypeFactory;
+import static org.apache.zest.api.property.IllegalTypeException.checkProhibited;
+
//import static org.apache.zest.functional.Iterables.empty;
//import static org.apache.zest.functional.Iterables.first;
@@ -65,6 +67,8 @@ import org.apache.zest.runtime.types.ValueTypeFactory;
public class PropertyModel
implements PropertyDescriptor, PropertyInfo, Binder, Visitable<PropertyModel>
{
+ private static boolean disallowProhibited = Boolean.getBoolean("zest.property.types.allow.prohibited");
+
private Type type;
private transient AccessibleObject accessor; // Interface accessor
@@ -106,6 +110,10 @@ public class PropertyModel
this.immutable = immutable;
this.metaInfo = metaInfo;
type = GenericPropertyInfo.propertyTypeOf( accessor );
+ if( PropertyModel.disallowProhibited && checkProhibited(type) )
+ {
+ throw new IllegalTypeException( type + "is not allowed as a Property type" );
+ }
this.accessor = accessor;
qualifiedName = QualifiedName.fromAccessor( accessor );
@@ -226,8 +234,7 @@ public class PropertyModel
ValueTypeFactory factory = ValueTypeFactory.instance();
Class<?> declaringClass = ( (Member) accessor() ).getDeclaringClass();
Class<?> mainType = resolution.model().types().findFirst().orElse( null );
- Serialization.Variant variant = findVariant();
- valueType = factory.newValueType( type(), declaringClass, mainType, resolution.layer(), resolution.module(), variant );
+ valueType = factory.newValueType( type(), declaringClass, mainType, resolution.layer(), resolution.module());
builderInfo = new BuilderPropertyInfo();
if( type instanceof TypeVariable )
{
@@ -235,21 +242,6 @@ public class PropertyModel
}
}
- private Serialization.Variant findVariant()
- {
- Serialization serialization = metaInfo.get( Serialization.class );
- Serialization.Variant variant = null;
- if( serialization != null )
- {
- variant = serialization.value();
- }
- if( variant == null )
- {
- variant = Serialization.Variant.entry;
- }
- return variant;
- }
-
@Override
public <ThrowableType extends Throwable> boolean accept( Visitor<? super PropertyModel, ThrowableType> visitor )
throws ThrowableType
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/runtime/src/main/java/org/apache/zest/runtime/types/ValueTypeFactory.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/zest/runtime/types/ValueTypeFactory.java b/core/runtime/src/main/java/org/apache/zest/runtime/types/ValueTypeFactory.java
index 427ce43..f19d618 100644
--- a/core/runtime/src/main/java/org/apache/zest/runtime/types/ValueTypeFactory.java
+++ b/core/runtime/src/main/java/org/apache/zest/runtime/types/ValueTypeFactory.java
@@ -31,7 +31,6 @@ import org.apache.zest.api.common.Visibility;
import org.apache.zest.api.type.CollectionType;
import org.apache.zest.api.type.EnumType;
import org.apache.zest.api.type.MapType;
-import org.apache.zest.api.type.Serialization;
import org.apache.zest.api.type.ValueCompositeType;
import org.apache.zest.api.type.ValueType;
import org.apache.zest.api.util.Classes;
@@ -64,8 +63,7 @@ public class ValueTypeFactory
Class declaringClass,
Class compositeType,
LayerModel layer,
- ModuleModel module,
- Serialization.Variant variant
+ ModuleModel module
)
{
ValueType valueType;
@@ -80,12 +78,12 @@ public class ValueTypeFactory
TypeVariable collectionTypeVariable = (TypeVariable) collectionType;
collectionType = Classes.resolveTypeVariable( collectionTypeVariable, declaringClass, compositeType );
}
- ValueType collectedType = newValueType( collectionType, declaringClass, compositeType, layer, module, variant );
+ ValueType collectedType = newValueType( collectionType, declaringClass, compositeType, layer, module );
valueType = new CollectionType( Classes.RAW_CLASS.apply( type ), collectedType );
}
else
{
- ValueType collectedType = newValueType( Object.class, declaringClass, compositeType, layer, module, variant );
+ ValueType collectedType = newValueType( Object.class, declaringClass, compositeType, layer, module );
valueType = new CollectionType( Classes.RAW_CLASS.apply( type ), collectedType );
}
}
@@ -100,21 +98,21 @@ public class ValueTypeFactory
TypeVariable keyTypeVariable = (TypeVariable) keyType;
keyType = Classes.resolveTypeVariable( keyTypeVariable, declaringClass, compositeType );
}
- ValueType keyedType = newValueType( keyType, declaringClass, compositeType, layer, module, variant );
+ ValueType keyedType = newValueType( keyType, declaringClass, compositeType, layer, module );
Type valType = pt.getActualTypeArguments()[ 1 ];
if( valType instanceof TypeVariable )
{
TypeVariable valueTypeVariable = (TypeVariable) valType;
valType = Classes.resolveTypeVariable( valueTypeVariable, declaringClass, compositeType );
}
- ValueType valuedType = newValueType( valType, declaringClass, compositeType, layer, module, variant );
- valueType = new MapType( Classes.RAW_CLASS.apply( type ), keyedType, valuedType, variant );
+ ValueType valuedType = newValueType( valType, declaringClass, compositeType, layer, module );
+ valueType = new MapType( Classes.RAW_CLASS.apply( type ), keyedType, valuedType );
}
else
{
- ValueType keyType = newValueType( Object.class, declaringClass, compositeType, layer, module, variant );
- ValueType valuesType = newValueType( Object.class, declaringClass, compositeType, layer, module, variant );
- valueType = new MapType( Classes.RAW_CLASS.apply( type ), keyType, valuesType, variant );
+ ValueType keyType = newValueType( Object.class, declaringClass, compositeType, layer, module );
+ ValueType valuesType = newValueType( Object.class, declaringClass, compositeType, layer, module );
+ valueType = new MapType( Classes.RAW_CLASS.apply( type ), keyType, valuesType );
}
}
else if( ValueCompositeType.isValueComposite( type ) )
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/runtime/src/test/java/org/apache/zest/bootstrap/InvalidTypesTest.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/zest/bootstrap/InvalidTypesTest.java b/core/runtime/src/test/java/org/apache/zest/bootstrap/InvalidTypesTest.java
new file mode 100644
index 0000000..103e182
--- /dev/null
+++ b/core/runtime/src/test/java/org/apache/zest/bootstrap/InvalidTypesTest.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ */
+
+package org.apache.zest.bootstrap;
+
+import org.apache.zest.api.activation.ActivationException;
+import org.apache.zest.api.common.InvalidApplicationException;
+import org.apache.zest.api.mixin.NoopMixin;
+import org.apache.zest.api.property.IllegalTypeException;
+import org.junit.Test;
+
+public class InvalidTypesTest
+{
+ public void givenMethodWithStringWhenDeclaringExpectOk()
+ throws Throwable
+ {
+ bootWith( Interface0.class );
+ }
+
+ @Test( expected = IllegalTypeException.class )
+ public void givenMethodWithJavaUtilDateWhenDeclaringExpectException()
+ throws Throwable
+ {
+ bootWith( Interface1.class );
+ }
+
+ @Test( expected = IllegalTypeException.class )
+ public void givenMethodWithJavaUtilCalendarWhenDeclaringExpectException()
+ throws Throwable
+ {
+ bootWith( Interface2.class );
+ }
+
+ @Test( expected = IllegalTypeException.class )
+ public void givenMethodWithJavaSqlTimeWhenDeclaringExpectException()
+ throws Throwable
+ {
+ bootWith( Interface3.class );
+ }
+
+ @Test( expected = IllegalTypeException.class )
+ public void givenMethodWithJavaSqlDateWhenDeclaringExpectException()
+ throws Throwable
+ {
+ bootWith( Interface4.class );
+ }
+
+ @Test( expected = IllegalTypeException.class )
+ public void givenMethodWithJavaTextDateFormatWhenDeclaringExpectException()
+ throws Throwable
+ {
+ bootWith( Interface5.class );
+ }
+
+ @Test( expected = IllegalTypeException.class )
+ public void givenMethodWithJavaTextSimpleDateFormatWhenDeclaringExpectException()
+ throws Throwable
+ {
+ bootWith( Interface6.class );
+ }
+
+ private void bootWith( Class<?> type )
+ throws Throwable
+ {
+ try
+ {
+ new SingletonAssembler()
+ {
+
+ @Override
+ public void assemble( ModuleAssembly module )
+ throws AssemblyException
+ {
+ module.values( type ).withMixins( NoopMixin.class );
+ }
+ };
+ }
+ catch( AssemblyException | ActivationException e )
+ {
+ Throwable cause = e.getCause();
+ if( cause instanceof InvalidApplicationException )
+ {
+ throw cause.getCause();
+ }
+
+ }
+ }
+
+ interface Interface0
+ {
+ void doSomething( String abc );
+ }
+
+ interface Interface1
+ {
+ void doSomething( java.util.Date arg1 );
+ }
+
+ interface Interface2
+ {
+ void doSomething( String abc, java.util.Calendar arg1 );
+ }
+
+ interface Interface3
+ {
+ void doSomething( String abc, java.sql.Time arg1 );
+ }
+
+ interface Interface4
+ {
+ void doSomething( String abc, java.sql.Date arg1 );
+ }
+
+ interface Interface5
+ {
+ void doSomething( String abc, java.text.DateFormat arg1 );
+ }
+
+ interface Interface6
+ {
+ void doSomething( String abc, java.text.SimpleDateFormat arg1 );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
index 93a8d7e..e9c8c75 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueDeserializerAdapter.java
@@ -48,7 +48,6 @@ import org.apache.zest.api.structure.ModuleDescriptor;
import org.apache.zest.api.type.CollectionType;
import org.apache.zest.api.type.EnumType;
import org.apache.zest.api.type.MapType;
-import org.apache.zest.api.type.Serialization;
import org.apache.zest.api.type.ValueCompositeType;
import org.apache.zest.api.type.ValueType;
import org.apache.zest.api.value.ValueBuilder;
@@ -81,10 +80,13 @@ import static org.apache.zest.functional.Iterables.empty;
* </p>
* <ul>
* <li>BigInteger and BigDecimal depends on {@link org.apache.zest.api.value.ValueSerializer.Options};</li>
- * <li>Date as String in ISO-8601, {@literal @millis@} or {@literal /Date(..)} Microsoft format;</li>
- * <li>DateTime (JodaTime) as a ISO-8601 String with optional timezone offset;</li>
- * <li>LocalDateTime (JodaTime) as whatever {@link LocalDateTime#parse} accept as {@literal instant};</li>
- * <li>LocalDate (JodaTime) as whatever {@link LocalDate#parse} accept as {@literal instant};</li>
+ * <li>ZonedDateTime as a ISO-8601 String with optional timezone name;</li>
+ * <li>OffsetDateTime as a ISO-8601 String with optional timezone offset;</li>
+ * <li>LocalDateTime as whatever {@link LocalDateTime#parse} accept as {@literal instant};</li>
+ * <li>LocalDate as whatever {@link LocalDate#parse} accept as {@literal instant};</li>
+ * <li>LocalTime as whatever {@link LocalTime#parse} accept as {@literal instant};</li>
+ * <li>Duration as a ISO-8601 String representing a {@link java.time.Duration}</li>
+ * <li>Period as a ISO-8601 String representing a {@link java.time.Period}</li>
* </ul>
*
* @param <InputType> Implementor pull-parser type
@@ -552,7 +554,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType>
module,
inputNode,
namedAssociationName,
- buildDeserializeInputNodeFunction( module, MapType.of( String.class, EntityReference.class, Serialization.Variant.object ) ) );
+ buildDeserializeInputNodeFunction( module, MapType.of( String.class, EntityReference.class ) ) );
stateMap.put( namedAssociationName, value );
}
}
@@ -620,15 +622,7 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType>
else // Explicit Map
if( MapType.class.isAssignableFrom( valueType.getClass() ) )
{
- MapType mapType = (MapType) valueType;
- if( mapType.variant().equals( Serialization.Variant.entry ) )
- {
- return (T) deserializeNodeEntryMap( module, (MapType) valueType, inputNode );
- }
- else
- {
- return (T) deserializeNodeObjectMap( module, (MapType) valueType, inputNode );
- }
+ return (T) deserializeNodeObjectMap( module, (MapType) valueType, inputNode );
}
else // Enum
if( EnumType.class.isAssignableFrom( valueType.getClass() ) || type.isEnum() )
@@ -715,18 +709,6 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType>
return collection;
}
- private <K, V> Map<K, V> deserializeNodeEntryMap( ModuleDescriptor module, MapType mapType, InputNodeType inputNode )
- throws Exception
- {
- Map<K, V> map = new HashMap<>();
- putArrayNodeInMap( module,
- inputNode,
- this.<K>buildDeserializeInputNodeFunction( module, mapType.keyType() ),
- this.<V>buildDeserializeInputNodeFunction( module, mapType.valueType() ),
- map );
- return map;
- }
-
private <V> Map<String, V> deserializeNodeObjectMap( ModuleDescriptor module, MapType mapType, InputNodeType inputNode )
throws Exception
{
@@ -966,14 +948,6 @@ public abstract class ValueDeserializerAdapter<InputType, InputNodeType>
)
throws Exception;
- protected abstract <K, V> void putArrayNodeInMap( ModuleDescriptor module,
- InputNodeType inputNode,
- Function<InputNodeType, K> keyDeserializer,
- Function<InputNodeType, V> valueDeserializer,
- Map<K, V> map
- )
- throws Exception;
-
protected abstract <V> void putObjectNodeInMap( ModuleDescriptor module,
InputNodeType inputNode,
Function<InputNodeType, V> valueDeserializer,
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java b/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
index e428f4e..8a223e5 100644
--- a/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
+++ b/core/spi/src/main/java/org/apache/zest/spi/value/ValueSerializerAdapter.java
@@ -86,7 +86,7 @@ public abstract class ValueSerializerAdapter<OutputType>
implements ValueSerializer
{
- public interface ComplexSerializer<T, OutputType>
+ interface ComplexSerializer<T, OutputType>
{
void serialize( Options options, T object, OutputType output )
throws Exception;
@@ -349,7 +349,7 @@ public abstract class ValueSerializerAdapter<OutputType>
{
onFieldStart( output, "_type" );
onValueStart( output );
- onValue( output, descriptor.valueType().types().findFirst().get().getName());
+ onValue( output, descriptor.valueType().types().findFirst().get().getName() );
onValueEnd( output );
onFieldEnd( output );
}
@@ -369,7 +369,7 @@ public abstract class ValueSerializerAdapter<OutputType>
throw new ValueSerializationException( "Unable to serialize property " + persistentProperty, e );
}
} );
- descriptor.valueType().associations().forEach(associationDescriptor -> {
+ descriptor.valueType().associations().forEach( associationDescriptor -> {
Association<?> association = state.associationFor( associationDescriptor.accessor() );
try
{
@@ -413,7 +413,7 @@ public abstract class ValueSerializerAdapter<OutputType>
{
throw new ValueSerializationException( "Unable to serialize manyassociation " + associationDescriptor, e );
}
- });
+ } );
descriptor.valueType().namedAssociations().forEach( associationDescriptor -> {
NamedAssociation<?> namedAssociation = state.namedAssociationFor( associationDescriptor.accessor() );
try
@@ -470,42 +470,16 @@ public abstract class ValueSerializerAdapter<OutputType>
@SuppressWarnings( "unchecked" )
Map<Object, Object> map = (Map<Object, Object>) object;
//noinspection ConstantConditions
- if( options.getBoolean( Options.MAP_ENTRIES_AS_OBJECTS ) )
- {
- onObjectStart( output );
- for( Map.Entry<Object, Object> entry : map.entrySet() )
- {
- onFieldStart( output, entry.getKey().toString() );
- onValueStart( output );
- doSerialize( options, entry.getValue(), output, false );
- onValueEnd( output );
- onFieldEnd( output );
- }
- onObjectEnd( output );
- }
- else
+ onObjectStart( output );
+ for( Map.Entry<Object, Object> entry : map.entrySet() )
{
- onArrayStart( output );
- for( Map.Entry<Object, Object> entry : map.entrySet() )
- {
- onObjectStart( output );
-
- onFieldStart( output, "key" );
- onValueStart( output );
- onValue( output, entry.getKey().toString() );
- onValueEnd( output );
- onFieldEnd( output );
-
- onFieldStart( output, "value" );
- onValueStart( output );
- doSerialize( options, entry.getValue(), output, false );
- onValueEnd( output );
- onFieldEnd( output );
-
- onObjectEnd( output );
- }
- onArrayEnd( output );
+ onFieldStart( output, entry.getKey().toString() );
+ onValueStart( output );
+ doSerialize( options, entry.getValue(), output, false );
+ onValueEnd( output );
+ onFieldEnd( output );
}
+ onObjectEnd( output );
}
private void serializeBase64Serializable( Object object, OutputType output )
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java b/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java
index 7b5eb4d..bd71cc4 100644
--- a/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java
+++ b/core/spi/src/main/java/org/apache/zest/valueserialization/orgjson/OrgJsonValueDeserializer.java
@@ -464,43 +464,6 @@ public class OrgJsonValueDeserializer
}
@Override
- protected <K, V> void putArrayNodeInMap( ModuleDescriptor module,
- Object inputNode,
- Function<Object, K> keyDeserializer,
- Function<Object, V> valueDeserializer,
- Map<K, V> map
- )
- throws Exception
- {
- if( JSONObject.NULL.equals( inputNode ) )
- {
- return;
- }
- if( !( inputNode instanceof JSONArray ) )
- {
- throw new ValueSerializationException( "Expected an array but got " + inputNode );
- }
- JSONArray array = (JSONArray) inputNode;
- for( int idx = 0; idx < array.length(); idx++ )
- {
- Object item = array.get( idx );
- if( !( item instanceof JSONObject ) )
- {
- throw new ValueSerializationException( "Expected an object but got " + inputNode );
- }
- JSONObject object = (JSONObject) item;
- Object keyNode = object.get( "key" );
- Object valueNode = object.get( "value" );
- K key = keyDeserializer.apply( keyNode );
- V value = valueDeserializer.apply( valueNode );
- if( key != null )
- {
- map.put( key, value );
- }
- }
- }
-
- @Override
protected <V> void putObjectNodeInMap( ModuleDescriptor module,
Object inputNode,
Function<Object, V> valueDeserializer,
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/extensions/valueserialization-jackson/src/main/java/org/apache/zest/valueserialization/jackson/JacksonValueDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/valueserialization-jackson/src/main/java/org/apache/zest/valueserialization/jackson/JacksonValueDeserializer.java b/extensions/valueserialization-jackson/src/main/java/org/apache/zest/valueserialization/jackson/JacksonValueDeserializer.java
index 5589467..2fb106f 100644
--- a/extensions/valueserialization-jackson/src/main/java/org/apache/zest/valueserialization/jackson/JacksonValueDeserializer.java
+++ b/extensions/valueserialization-jackson/src/main/java/org/apache/zest/valueserialization/jackson/JacksonValueDeserializer.java
@@ -312,41 +312,6 @@ public class JacksonValueDeserializer
}
@Override
- protected <K, V> void putArrayNodeInMap( ModuleDescriptor module,
- JsonNode inputNode,
- Function<JsonNode, K> keyDeserializer,
- Function<JsonNode, V> valueDeserializer,
- Map<K, V> map
- )
- throws Exception
- {
- if( isNullOrMissing( inputNode ) )
- {
- return;
- }
- if( !inputNode.isArray() )
- {
- throw new ValueSerializationException( "Expected an array but got " + inputNode );
- }
- ArrayNode array = (ArrayNode) inputNode;
- for( JsonNode item : array )
- {
- if( !item.isObject() )
- {
- throw new ValueSerializationException( "Expected an object but got " + inputNode );
- }
- JsonNode keyNode = item.get( "key" );
- JsonNode valueNode = item.get( "value" );
- K key = keyDeserializer.apply( keyNode );
- V value = valueDeserializer.apply( valueNode );
- if( key != null )
- {
- map.put( key, value );
- }
- }
- }
-
- @Override
protected <V> void putObjectNodeInMap( ModuleDescriptor module,
JsonNode inputNode,
Function<JsonNode, V> valueDeserializer,
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/extensions/valueserialization-stax/src/main/java/org/apache/zest/valueserialization/stax/StaxValueDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/valueserialization-stax/src/main/java/org/apache/zest/valueserialization/stax/StaxValueDeserializer.java b/extensions/valueserialization-stax/src/main/java/org/apache/zest/valueserialization/stax/StaxValueDeserializer.java
index 85a159e..d1c17c6 100644
--- a/extensions/valueserialization-stax/src/main/java/org/apache/zest/valueserialization/stax/StaxValueDeserializer.java
+++ b/extensions/valueserialization-stax/src/main/java/org/apache/zest/valueserialization/stax/StaxValueDeserializer.java
@@ -404,35 +404,6 @@ public class StaxValueDeserializer
}
@Override
- protected <K, V> void putArrayNodeInMap( ModuleDescriptor module,
- Node inputNode,
- Function<Node, K> keyDeserializer,
- Function<Node, V> valueDeserializer, Map<K, V> map
- )
- throws Exception
- {
- if( inputNode == null )
- {
- return;
- }
- if( !"array".equals( inputNode.getLocalName() ) )
- {
- throw new ValueSerializationException( "Expected an <array/> but got " + inputNode );
- }
- NodeList entriesNodes = inputNode.getChildNodes();
- for( int idx = 0; idx < entriesNodes.getLength(); idx++ )
- {
- Node entryNode = entriesNodes.item( idx );
- K key = getObjectFieldValue( module, entryNode, "key", keyDeserializer );
- V value = getObjectFieldValue( module, entryNode, "value", valueDeserializer );
- if( key != null )
- {
- map.put( key, value );
- }
- }
- }
-
- @Override
protected <V> void putObjectNodeInMap( ModuleDescriptor module,
Node inputNode,
Function<Node, V> valueDeserializer,
http://git-wip-us.apache.org/repos/asf/zest-java/blob/65c7df37/libraries/restlet/src/main/java/org/apache/zest/library/restlet/serialization/JsonRepresentation.java
----------------------------------------------------------------------
diff --git a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/serialization/JsonRepresentation.java b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/serialization/JsonRepresentation.java
index 1527d90..71eaa12 100644
--- a/libraries/restlet/src/main/java/org/apache/zest/library/restlet/serialization/JsonRepresentation.java
+++ b/libraries/restlet/src/main/java/org/apache/zest/library/restlet/serialization/JsonRepresentation.java
@@ -42,7 +42,7 @@ import org.restlet.representation.Representation;
public class JsonRepresentation<T> extends OutputRepresentation
{
- private static final ValueSerializer.Options OPTIONS_NO_TYPE = new ValueSerializer.Options().withoutTypeInfo().withMapEntriesAsObjects();
+ private static final ValueSerializer.Options OPTIONS_NO_TYPE = new ValueSerializer.Options().withoutTypeInfo();
@Structure
private ZestSPI spi;