polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [3/3] polygene-java git commit: Property Serialization Converters can now be registered at assembly time
Date Sun, 14 May 2017 13:38:13 GMT
Property Serialization Converters can now be registered at assembly time

e.g.:

  module.values( SomeValue.class );
  module.forMixin( SomeValue.class )
        .setMetaInfo( new CustomPropertyConverter() )
        .declareDefaults()
        .customAssemblyConvertedProperty();

POLYGENE-240


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/a14bde4a
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/a14bde4a
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/a14bde4a

Branch: refs/heads/develop
Commit: a14bde4aa28bbbb6fb6ead8526e7c89cae57c7db
Parents: 5eb7929
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Sun May 14 15:37:51 2017 +0200
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sun May 14 15:37:51 2017 +0200

----------------------------------------------------------------------
 .../polygene/api/serialization/Converters.java  | 67 +++++++++++++++++---
 .../javaxjson/JavaxJsonDeserializer.java        | 15 +----
 .../javaxjson/JavaxJsonSerializer.java          | 12 +---
 .../AbstractConvertersSerializationTest.java    | 16 ++++-
 .../javaxxml/JavaxXmlDeserializer.java          | 15 +----
 .../javaxxml/JavaxXmlSerializer.java            | 12 +---
 .../messagepack/MessagePackDeserializer.java    | 15 +----
 .../messagepack/MessagePackSerializer.java      | 12 +---
 8 files changed, 89 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/core/api/src/main/java/org/apache/polygene/api/serialization/Converters.java
----------------------------------------------------------------------
diff --git a/core/api/src/main/java/org/apache/polygene/api/serialization/Converters.java
b/core/api/src/main/java/org/apache/polygene/api/serialization/Converters.java
index 77206c5..44a1232 100644
--- a/core/api/src/main/java/org/apache/polygene/api/serialization/Converters.java
+++ b/core/api/src/main/java/org/apache/polygene/api/serialization/Converters.java
@@ -21,6 +21,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.apache.polygene.api.mixin.Mixins;
+import org.apache.polygene.api.structure.MetaInfoHolder;
 import org.apache.polygene.api.type.HasTypes;
 import org.apache.polygene.api.type.ValueType;
 import org.apache.polygene.api.util.Annotations;
@@ -52,18 +53,40 @@ public interface Converters
      */
     <T> Converter<T> converterFor( ValueType valueType );
 
+    /**
+     * Find a matching converter amongst registered ones.
+     *
+     * See {@link org.apache.polygene.api.type.HasTypesCollectors#closestType(HasTypes)}.
+     *
+     * @param type the value type
+     * @param <T> the converted type
+     * @return the closest matching registered converter, or {@literal null} if none
+     */
     default <T> Converter<T> converterFor( Class<? extends T> type )
     {
         return converterFor( ValueType.of( type ) );
     }
 
     /**
+     * Find converter registered as meta-info.
+     *
+     * Meta-info converters are registered either using {@link ConvertedBy} annotation or
at assembly time.
+     * The latter takes precedence over the former.
+     *
+     * @param metaInfoHolder the meta-info holder, e.g. a property descriptor
+     * @param <T> the converted type
+     * @return the registered converted, or {@literal null} if none
+     */
+    <T> Converter<T> converterFor( MetaInfoHolder metaInfoHolder );
+
+    /**
      * Serialization Converters default Mixin.
      */
     class Mixin implements Converters
     {
         private final Map<ValueType, Converter<?>> converters = new LinkedHashMap<>();
         private final Map<ValueType, Converter<?>> resolvedConvertersCache =
new HashMap<>();
+        private final Map<Class<? extends Converter>, Converter<?>> convertersInstancesCache
= new HashMap<>();
 
         @Override
         public void registerConverter( ValueType valueType, Converter<?> converter
)
@@ -102,24 +125,50 @@ public interface Converters
             return converter;
         }
 
+        @Override
+        public <T> Converter<T> converterFor( MetaInfoHolder metaInfoHolder )
+        {
+            Converter converter = metaInfoHolder.metaInfo( Converter.class );
+            if( converter != null )
+            {
+                return castConverter( converter );
+            }
+            ConvertedBy convertedBy = metaInfoHolder.metaInfo( ConvertedBy.class );
+            if( convertedBy != null )
+            {
+                return converterInstanceOf( convertedBy.value() );
+            }
+            return null;
+        }
+
         private <T> Converter<T> lookupConvertedByConverter( ValueType valueType
)
         {
             ConvertedBy convertedBy = Annotations.annotationOn( valueType.primaryType(),
ConvertedBy.class );
             if( convertedBy != null )
             {
-                Class<? extends Converter> converterClass = convertedBy.value();
-                try
-                {
-                    return castConverter( converterClass.newInstance() );
-                }
-                catch( IllegalAccessException | InstantiationException e )
-                {
-                    throw new IllegalArgumentException( "Cannot use class " + converterClass
+ " as Converter", e );
-                }
+                return converterInstanceOf( convertedBy.value() );
             }
             return null;
         }
 
+        private <T> Converter<T> converterInstanceOf( Class<? extends Converter>
converterClass )
+        {
+            if( convertersInstancesCache.containsKey( converterClass ) )
+            {
+                return castConverter( convertersInstancesCache.get( converterClass ) );
+            }
+            try
+            {
+                Converter<T> converter = castConverter( converterClass.newInstance()
);
+                convertersInstancesCache.put( converterClass, converter );
+                return converter;
+            }
+            catch( InstantiationException | IllegalAccessException ex )
+            {
+                throw new SerializationException( "Unable to instantiate Converter: " + converterClass.getName(),
ex );
+            }
+        }
+
         @SuppressWarnings( "unchecked" )
         private <T> Converter<T> castConverter( Converter<?> converter
)
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
index 557490b..ad647a4 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
@@ -50,7 +50,6 @@ import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.mixin.Initializable;
 import org.apache.polygene.api.property.PropertyDescriptor;
-import org.apache.polygene.api.serialization.ConvertedBy;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.SerializationException;
@@ -61,7 +60,6 @@ import org.apache.polygene.api.type.CollectionType;
 import org.apache.polygene.api.type.MapType;
 import org.apache.polygene.api.type.StatefulAssociationValueType;
 import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.api.util.Annotations;
 import org.apache.polygene.api.value.ValueBuilder;
 import org.apache.polygene.spi.serialization.AbstractTextDeserializer;
 import org.apache.polygene.spi.serialization.JsonDeserializer;
@@ -191,12 +189,6 @@ public class JavaxJsonDeserializer extends AbstractTextDeserializer
         {
             return null;
         }
-        ConvertedBy convertedBy = Annotations.annotationOn( valueType.primaryType(), ConvertedBy.class
);
-        if( convertedBy != null )
-        {
-            return (T) module.instance().newObject( convertedBy.value() )
-                             .fromString( doDeserialize( module, ValueType.STRING, json ).toString()
);
-        }
         Converter<Object> converter = converters.converterFor( valueType );
         if( converter != null )
         {
@@ -345,11 +337,10 @@ public class JavaxJsonDeserializer extends AbstractTextDeserializer
             if( jsonValue != null )
             {
                 Object value;
-                ConvertedBy convertedBy = property.metaInfo( ConvertedBy.class );
-                if( convertedBy != null )
+                Converter converter = converters.converterFor( property );
+                if( converter != null )
                 {
-                    value = module.instance().newObject( convertedBy.value() )
-                                  .fromString( doDeserialize( module, ValueType.STRING, jsonValue
) );
+                    value = converter.fromString( doDeserialize( module, ValueType.STRING,
jsonValue ) );
                 }
                 else
                 {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
index 02b88a9..0222f9c 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
@@ -38,16 +38,13 @@ import org.apache.polygene.api.common.Optional;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.CompositeInstance;
 import org.apache.polygene.api.composite.StatefulAssociationCompositeDescriptor;
-import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.mixin.Initializable;
-import org.apache.polygene.api.serialization.ConvertedBy;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.service.ServiceDescriptor;
-import org.apache.polygene.api.structure.Module;
 import org.apache.polygene.api.type.ArrayType;
 import org.apache.polygene.api.type.MapType;
 import org.apache.polygene.api.type.StatefulAssociationValueType;
@@ -75,9 +72,6 @@ public class JavaxJsonSerializer extends AbstractTextSerializer
     @Uses
     private ServiceDescriptor descriptor;
 
-    @Structure
-    private Module module;
-
     private JavaxJsonSettings settings;
 
     @Override
@@ -173,10 +167,10 @@ public class JavaxJsonSerializer extends AbstractTextSerializer
             property ->
             {
                 Object value = state.propertyFor( property.accessor() ).get();
-                ConvertedBy convertedBy = property.metaInfo( ConvertedBy.class );
-                if( convertedBy != null )
+                Converter converter = converters.converterFor( property );
+                if( converter != null )
                 {
-                    value = module.newObject( convertedBy.value() ).toString( value );
+                    value = converter.toString( value );
                 }
                 builder.add( property.qualifiedName().name(), doSerialize( options, value,
false ) );
             } );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractConvertersSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractConvertersSerializationTest.java
b/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractConvertersSerializationTest.java
index f8b6834..254196f 100644
--- a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractConvertersSerializationTest.java
+++ b/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractConvertersSerializationTest.java
@@ -37,7 +37,10 @@ public abstract class AbstractConvertersSerializationTest extends AbstractPolyge
     public void assemble( ModuleAssembly module )
     {
         module.values( SomeValue.class );
-        module.objects( CustomPlainValueConverter.class, CustomPropertyConverter.class );
+        module.forMixin( SomeValue.class )
+              .setMetaInfo( new CustomPropertyConverter() )
+              .declareDefaults()
+              .customAssemblyConvertedProperty();
     }
 
     protected abstract String getStringFromValueState( String state, String key ) throws
Exception;
@@ -48,6 +51,8 @@ public abstract class AbstractConvertersSerializationTest extends AbstractPolyge
 
         @ConvertedBy( CustomPropertyConverter.class )
         Property<String> customConvertedProperty();
+
+        Property<String> customAssemblyConvertedProperty();
     }
 
     @ConvertedBy( CustomPlainValueConverter.class )
@@ -132,11 +137,16 @@ public abstract class AbstractConvertersSerializationTest extends AbstractPolyge
         ValueBuilder<SomeValue> builder = valueBuilderFactory.newValueBuilder( SomeValue.class
);
         builder.prototype().customPlainValue().set( new CustomPlainValue( "foo" ) );
         builder.prototype().customConvertedProperty().set( "bar" );
+        builder.prototype().customAssemblyConvertedProperty().set( "bazar" );
         SomeValue value = builder.newInstance();
 
         String serialized = serialization.serialize( value );
-        assertThat( getStringFromValueState( serialized, "customPlainValue" ), equalTo( rot13(
"foo" ) ) );
-        assertThat( getStringFromValueState( serialized, "customConvertedProperty" ), equalTo(
rot13( "bar" ) ) );
+        assertThat( getStringFromValueState( serialized, "customPlainValue" ),
+                    equalTo( rot13( "foo" ) ) );
+        assertThat( getStringFromValueState( serialized, "customConvertedProperty" ),
+                    equalTo( rot13( "bar" ) ) );
+        assertThat( getStringFromValueState( serialized, "customAssemblyConvertedProperty"
),
+                    equalTo( rot13( "bazar" ) ) );
 
         SomeValue deserialized = serialization.deserialize( module, SomeValue.class, serialized
);
         assertThat( deserialized, equalTo( value ) );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
index a4863c0..1c9d64e 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
@@ -45,7 +45,6 @@ import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.mixin.Initializable;
 import org.apache.polygene.api.property.PropertyDescriptor;
-import org.apache.polygene.api.serialization.ConvertedBy;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.SerializationException;
@@ -57,7 +56,6 @@ import org.apache.polygene.api.type.EnumType;
 import org.apache.polygene.api.type.MapType;
 import org.apache.polygene.api.type.StatefulAssociationValueType;
 import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.api.util.Annotations;
 import org.apache.polygene.api.value.ValueBuilder;
 import org.apache.polygene.spi.serialization.AbstractTextDeserializer;
 import org.apache.polygene.spi.serialization.XmlDeserializer;
@@ -134,12 +132,6 @@ public class JavaxXmlDeserializer extends AbstractTextDeserializer
         {
             return null;
         }
-        ConvertedBy convertedBy = Annotations.annotationOn( valueType.primaryType(), ConvertedBy.class
);
-        if( convertedBy != null )
-        {
-            return (T) module.instance().newObject( convertedBy.value() )
-                             .fromString( doDeserialize( module, ValueType.STRING, xml ).toString()
);
-        }
         Converter<Object> converter = converters.converterFor( valueType );
         if( converter != null )
         {
@@ -208,11 +200,10 @@ public class JavaxXmlDeserializer extends AbstractTextDeserializer
             {
                 Node valueNode = JavaxXml.firstStateChildNode( element.get() ).orElse( null
);
                 Object value;
-                ConvertedBy convertedBy = property.metaInfo( ConvertedBy.class );
-                if( convertedBy != null )
+                Converter<Object> converter = converters.converterFor( property );
+                if( converter != null )
                 {
-                    value = module.instance().newObject( convertedBy.value() )
-                                  .fromString( doDeserialize( module, ValueType.STRING, valueNode
) );
+                    value = converter.fromString( doDeserialize( module, ValueType.STRING,
valueNode ) );
                 }
                 else
                 {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
index 927359a..d1f8beb 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
@@ -35,16 +35,13 @@ import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.CompositeInstance;
 import org.apache.polygene.api.composite.StatefulAssociationCompositeDescriptor;
 import org.apache.polygene.api.entity.EntityReference;
-import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.mixin.Initializable;
-import org.apache.polygene.api.serialization.ConvertedBy;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.service.ServiceDescriptor;
-import org.apache.polygene.api.structure.Module;
 import org.apache.polygene.api.type.ArrayType;
 import org.apache.polygene.api.type.EnumType;
 import org.apache.polygene.api.type.MapType;
@@ -80,9 +77,6 @@ public class JavaxXmlSerializer extends AbstractTextSerializer
     @Uses
     private ServiceDescriptor descriptor;
 
-    @Structure
-    private Module module;
-
     private JavaxXmlSettings settings;
 
     @Override
@@ -195,10 +189,10 @@ public class JavaxXmlSerializer extends AbstractTextSerializer
             property ->
             {
                 Object value = state.propertyFor( property.accessor() ).get();
-                ConvertedBy convertedBy = property.metaInfo( ConvertedBy.class );
-                if( convertedBy != null )
+                Converter<Object> converter = converters.converterFor( property );
+                if( converter != null )
                 {
-                    value = module.newObject( convertedBy.value() ).toString( value );
+                    value = converter.toString( value );
                 }
                 Element element = document.createElement( property.qualifiedName().name()
);
                 element.appendChild( doSerialize( document, options, value, false ) );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackDeserializer.java
b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackDeserializer.java
index c0ad355..90d9586 100644
--- a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackDeserializer.java
+++ b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackDeserializer.java
@@ -39,7 +39,6 @@ import org.apache.polygene.api.entity.EntityReference;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.mixin.Mixins;
 import org.apache.polygene.api.property.PropertyDescriptor;
-import org.apache.polygene.api.serialization.ConvertedBy;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.Deserializer;
@@ -51,7 +50,6 @@ import org.apache.polygene.api.type.EnumType;
 import org.apache.polygene.api.type.MapType;
 import org.apache.polygene.api.type.StatefulAssociationValueType;
 import org.apache.polygene.api.type.ValueType;
-import org.apache.polygene.api.util.Annotations;
 import org.apache.polygene.api.value.ValueBuilder;
 import org.apache.polygene.spi.serialization.AbstractBinaryDeserializer;
 import org.msgpack.core.MessagePack;
@@ -104,12 +102,6 @@ public interface MessagePackDeserializer extends Deserializer
                 {
                     return null;
                 }
-                ConvertedBy convertedBy = Annotations.annotationOn( valueType.primaryType(),
ConvertedBy.class );
-                if( convertedBy != null )
-                {
-                    return (T) module.instance().newObject( convertedBy.value() )
-                                     .fromString( doDeserialize( module, ValueType.STRING,
value ).toString() );
-                }
                 Converter<Object> converter = converters.converterFor( valueType );
                 if( converter != null )
                 {
@@ -239,11 +231,10 @@ public interface MessagePackDeserializer extends Deserializer
                 if( messagePackValue != null )
                 {
                     Object value;
-                    ConvertedBy convertedBy = property.metaInfo( ConvertedBy.class );
-                    if( convertedBy != null )
+                    Converter<Object> converter = converters.converterFor( property
);
+                    if( converter != null )
                     {
-                        value = module.instance().newObject( convertedBy.value() )
-                                      .fromString( doDeserialize( module, ValueType.STRING,
messagePackValue ) );
+                        value = converter.fromString( doDeserialize( module, ValueType.STRING,
messagePackValue ) );
                     }
                     else
                     {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/a14bde4a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackSerializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackSerializer.java
b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackSerializer.java
index 9e539bf..68c9a99 100644
--- a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackSerializer.java
+++ b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/MessagePackSerializer.java
@@ -28,15 +28,12 @@ import org.apache.polygene.api.common.Optional;
 import org.apache.polygene.api.composite.Composite;
 import org.apache.polygene.api.composite.CompositeInstance;
 import org.apache.polygene.api.composite.StatefulAssociationCompositeDescriptor;
-import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.mixin.Mixins;
-import org.apache.polygene.api.serialization.ConvertedBy;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.serialization.Serializer;
-import org.apache.polygene.api.structure.Module;
 import org.apache.polygene.api.type.ArrayType;
 import org.apache.polygene.api.type.EnumType;
 import org.apache.polygene.api.type.MapType;
@@ -64,9 +61,6 @@ public interface MessagePackSerializer extends Serializer
         @This
         private MessagePackAdapters adapters;
 
-        @Structure
-        private Module module;
-
         @Override
         public void serialize( Options options, OutputStream output, @Optional Object object
)
         {
@@ -146,10 +140,10 @@ public interface MessagePackSerializer extends Serializer
                 property ->
                 {
                     Object value = state.propertyFor( property.accessor() ).get();
-                    ConvertedBy convertedBy = property.metaInfo( ConvertedBy.class );
-                    if( convertedBy != null )
+                    Converter<Object> converter = converters.converterFor( property
);
+                    if( converter != null )
                     {
-                        value = module.newObject( convertedBy.value() ).toString( value );
+                        value = converter.toString( value );
                     }
                     builder.put(
                         ValueFactory.newString( property.qualifiedName().name() ),


Mime
View raw message