polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [39/51] [abbrv] polygene-java git commit: Assembly time registration of serialization Converters
Date Sun, 02 Apr 2017 17:46:19 GMT
Assembly time registration of serialization Converters

POLYGENE-231


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

Branch: refs/heads/serialization-3.0
Commit: d3ec800f44bd5b17ab9bd8d4aa129938cb486b57
Parents: 1a62b3e
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Mar 13 12:25:24 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Sun Apr 2 19:16:23 2017 +0200

----------------------------------------------------------------------
 .../JavaxJsonSerializationService.java          |  23 +--
 .../javaxjson/JavaxJsonSettings.java            |   3 +-
 .../serialization/SerializationSettings.java    |  60 ++++++
 .../AbstractPlainValueSerializationTest.java    | 185 +++++++++++++------
 .../JavaxJsonPlainValueSerializationTest.java   |   9 +
 .../javaxxml/JavaxXmlSerializationService.java  |  23 +--
 .../javaxxml/JavaxXmlSettings.java              |   3 +-
 .../JavaxXmlPlainValueSerializationTest.java    |   4 +-
 .../MessagePackSerializationService.java        |  23 +--
 .../msgpack/MessagePackSettings.java            |   3 +-
 .../MessagePackPlainValueSerializationTest.java |   4 +-
 11 files changed, 237 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
index 2618db7..4c43039 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializationService.java
@@ -59,10 +59,9 @@ public interface JavaxJsonSerializationService extends JavaxJsonSerialization,
S
         {
             if( !registrationDone )
             {
-                registerCustomConverters();
+                applySettings();
                 registerBuiltInConverters();
-                registerCustomAdapters();
-                registerBaseAdapters();
+                registerBaseJavaxJsonAdapters();
                 registrationDone = true;
             }
         }
@@ -70,9 +69,14 @@ public interface JavaxJsonSerializationService extends JavaxJsonSerialization,
S
         @Override
         public void passivateService() {}
 
-        private void registerCustomConverters()
+        private void applySettings()
         {
-            // TODO register custom converters
+            JavaxJsonSettings settings
+                = JavaxJsonSettings.orDefault( descriptor.metaInfo( JavaxJsonSettings.class
) );
+            settings.getConverters()
+                    .forEach( ( type, converter ) -> converters.registerConverter( type,
converter ) );
+            settings.getAdapters()
+                    .forEach( ( type, adapter ) -> adapters.registerAdapter( type, adapter
) );
         }
 
         private void registerBuiltInConverters()
@@ -80,14 +84,7 @@ public interface JavaxJsonSerializationService extends JavaxJsonSerialization,
S
             builtInConverters.registerBuiltInConverters( converters );
         }
 
-        private void registerCustomAdapters()
-        {
-            JavaxJsonSettings.orDefault( descriptor.metaInfo( JavaxJsonSettings.class ) )
-                             .getAdapters()
-                             .forEach( ( valueType, adapter ) -> adapters.registerAdapter(
valueType, adapter ) );
-        }
-
-        private void registerBaseAdapters()
+        private void registerBaseJavaxJsonAdapters()
         {
             // Primitive Value types
             adapters.registerAdapter( ValueType.STRING, new StringAdapter() );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSettings.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSettings.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSettings.java
index e0f993d..7042638 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSettings.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSettings.java
@@ -20,8 +20,9 @@ package org.apache.polygene.serialization.javaxjson;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.serialization.SerializationSettings;
 
-public class JavaxJsonSettings
+public class JavaxJsonSettings extends SerializationSettings<JavaxJsonSettings>
 {
     public static final JavaxJsonSettings DEFAULT = new JavaxJsonSettings();
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/core/spi/src/main/java/org/apache/polygene/spi/serialization/SerializationSettings.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/spi/serialization/SerializationSettings.java
b/core/spi/src/main/java/org/apache/polygene/spi/serialization/SerializationSettings.java
new file mode 100644
index 0000000..cba63a4
--- /dev/null
+++ b/core/spi/src/main/java/org/apache/polygene/spi/serialization/SerializationSettings.java
@@ -0,0 +1,60 @@
+/*
+ *  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.polygene.spi.serialization;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.polygene.api.serialization.Converter;
+import org.apache.polygene.api.type.ValueType;
+
+/**
+ * Serialization Settings.
+ *
+ * Serialization implementations might extend this with additional specialized settings.
+ *
+ * @param <SettingsType> Specialization type of SerializationSettings for a fluent
usage
+ */
+public class SerializationSettings<SettingsType extends SerializationSettings>
+{
+    public static final SerializationSettings DEFAULT = new SerializationSettings();
+
+    public static SerializationSettings orDefault( SerializationSettings settings )
+    {
+        return settings != null ? settings : DEFAULT;
+    }
+
+    private final Map<ValueType, Converter<Object>> converters = new LinkedHashMap<>();
+
+    public final Map<ValueType, Converter<Object>> getConverters()
+    {
+        return Collections.unmodifiableMap( converters );
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public final SettingsType withConverter( ValueType valueType, Converter<Object>
adapter )
+    {
+        converters.put( valueType, adapter );
+        return (SettingsType) this;
+    }
+
+    public final SettingsType withConverter( Converter<Object> adapter )
+    {
+        return withConverter( ValueType.of( adapter.type() ), adapter );
+    }
+}

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
b/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
index 8f3ad6a..8822a82 100644
--- a/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
+++ b/core/testsupport/src/main/java/org/apache/polygene/test/serialization/AbstractPlainValueSerializationTest.java
@@ -31,12 +31,15 @@ import java.time.Period;
 import java.time.ZoneId;
 import java.time.ZoneOffset;
 import java.time.ZonedDateTime;
+import java.util.Objects;
 import org.apache.polygene.api.entity.EntityReference;
 import org.apache.polygene.api.injection.scope.Service;
+import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Serialization;
 import org.apache.polygene.api.type.EnumType;
 import org.apache.polygene.api.type.ValueType;
 import org.apache.polygene.bootstrap.ModuleAssembly;
+import org.apache.polygene.spi.serialization.SerializationSettings;
 import org.apache.polygene.test.AbstractPolygeneTest;
 import org.junit.Test;
 
@@ -48,15 +51,26 @@ import static org.junit.Assert.assertThat;
 
 /**
  * Assert that ValueSerialization behaviour on plain values is correct.
+ *
+ * Implementations must:
+ * <ul>
+ *     <li>implement {@link #assemble(ModuleAssembly)}</li>
+ *     <li>
+ *         apply test {@link SerializationSettings} using {@link #withTestSettings(SerializationSettings)}
+ *         in {@literal assemble()}
+ *     </li>
+ *     <li>implement {@link #getSingleStringRawState(String)}</li>
+ * </ul>
  */
 public abstract class AbstractPlainValueSerializationTest extends AbstractPolygeneTest
 {
     @Service
-    protected Serialization stateSerialization;
+    protected Serialization serialization;
 
-    @Override
-    public void assemble( ModuleAssembly module )
+    @SuppressWarnings( "unchecked" )
+    protected <T extends SerializationSettings> T withTestSettings( T settings )
     {
+        return (T) settings.withConverter( new CustomConverter() );
     }
 
     protected abstract String getSingleStringRawState( String state ) throws Exception;
@@ -64,22 +78,22 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
     @Test
     public void givenNullValueWhenSerializingAndDeserializingExpectNull()
     {
-        String output = stateSerialization.serialize( null );
+        String output = serialization.serialize( null );
         System.out.println( output );
 
-        assertThat( stateSerialization.deserialize( module, ValueType.of( Integer.class ),
output ), nullValue() );
-        assertThat( stateSerialization.deserialize( module, ValueType.of( String.class ),
output ), nullValue() );
-        assertThat( stateSerialization.deserialize( module, ValueType.of( SomeEnum.class
), output ), nullValue() );
+        assertThat( serialization.deserialize( module, ValueType.of( Integer.class ), output
), nullValue() );
+        assertThat( serialization.deserialize( module, ValueType.of( String.class ), output
), nullValue() );
+        assertThat( serialization.deserialize( module, ValueType.of( SomeEnum.class ), output
), nullValue() );
     }
 
     @Test
     public void givenEnumValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String output = stateSerialization.serialize( SomeEnum.BÆR );
+        String output = serialization.serialize( SomeEnum.BÆR );
         System.out.println( output );
         assertThat( getSingleStringRawState( output ), equalTo( "BÆR" ) );
 
-        SomeEnum value = stateSerialization.deserialize( module, EnumType.of( SomeEnum.class
), output );
+        SomeEnum value = serialization.deserialize( module, EnumType.of( SomeEnum.class ),
output );
         assertThat( value, is( SomeEnum.BÆR ) );
     }
 
@@ -98,116 +112,116 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
 
     private <P, B> void assertPrimitiveBoxedDeserializationEquals( Class<P> primitiveType,
Class<B> boxedType, P value )
     {
-        String serialized = stateSerialization.serialize( value );
+        String serialized = serialization.serialize( value );
         System.out.println( serialized );
 
-        B boxed = stateSerialization.deserialize( module, boxedType, serialized );
-        P primitive = stateSerialization.deserialize( module, primitiveType, serialized );
+        B boxed = serialization.deserialize( module, boxedType, serialized );
+        P primitive = serialization.deserialize( module, primitiveType, serialized );
         assertThat( "Primitive/Boxed", boxed, equalTo( primitive ) );
     }
 
     @Test
     public void givenCharacterValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( '∫' );
+        String serialized = serialization.serialize( '∫' );
         System.out.println( serialized );
 
-        Character deserialized = stateSerialization.deserialize( module, Character.class,
serialized );
+        Character deserialized = serialization.deserialize( module, Character.class, serialized
);
         assertThat( "Deserialized", deserialized, equalTo( '∫' ) );
 
-        deserialized = stateSerialization.deserialize( module, char.class, serialized );
+        deserialized = serialization.deserialize( module, char.class, serialized );
         assertThat( "Deserialized", deserialized, is( '∫' ) );
     }
 
     @Test
     public void givenEmptyStringValueWhenSerializingAndDeserializingExpectEquals() throws
Exception
     {
-        String serialized = stateSerialization.serialize( "" );
+        String serialized = serialization.serialize( "" );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "" ) );
 
-        String deserialized = stateSerialization.deserialize( module, String.class, serialized
);
+        String deserialized = serialization.deserialize( module, String.class, serialized
);
         assertThat( "Deserialized", deserialized, equalTo( "" ) );
     }
 
     @Test
     public void givenStringValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( "Å∫" );
+        String serialized = serialization.serialize( "Å∫" );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "Å∫" ) );
 
-        String deserialized = stateSerialization.deserialize( module, String.class, serialized
);
+        String deserialized = serialization.deserialize( module, String.class, serialized
);
         assertThat( deserialized, equalTo( "Å∫" ) );
     }
 
     @Test
     public void givenBooleanValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( true );
+        String serialized = serialization.serialize( true );
         System.out.println( serialized );
 
-        Boolean deserialized = stateSerialization.deserialize( module, Boolean.class, serialized
);
+        Boolean deserialized = serialization.deserialize( module, Boolean.class, serialized
);
         assertThat( deserialized, equalTo( Boolean.TRUE ) );
     }
 
     @Test
     public void givenIntegerValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( 42 );
+        String serialized = serialization.serialize( 42 );
         System.out.println( serialized );
 
-        Integer deserialized = stateSerialization.deserialize( module, Integer.class, serialized
);
+        Integer deserialized = serialization.deserialize( module, Integer.class, serialized
);
         assertThat( deserialized, equalTo( 42 ) );
     }
 
     @Test
     public void givenLongValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( 42L );
+        String serialized = serialization.serialize( 42L );
         System.out.println( serialized );
 
-        Long deserialized = stateSerialization.deserialize( module, Long.class, serialized
);
+        Long deserialized = serialization.deserialize( module, Long.class, serialized );
         assertThat( deserialized, equalTo( 42L ) );
     }
 
     @Test
     public void givenShortValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( (short) 42 );
+        String serialized = serialization.serialize( (short) 42 );
         System.out.println( serialized );
 
-        Short deserialized = stateSerialization.deserialize( module, Short.class, serialized
);
+        Short deserialized = serialization.deserialize( module, Short.class, serialized );
         assertThat( deserialized, equalTo( (short) 42 ) );
     }
 
     @Test
     public void givenByteValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( (byte) 42 );
+        String serialized = serialization.serialize( (byte) 42 );
         System.out.println( serialized );
 
-        Byte deserialized = stateSerialization.deserialize( module, Byte.class, serialized
);
+        Byte deserialized = serialization.deserialize( module, Byte.class, serialized );
         assertThat( deserialized, equalTo( (byte) 42 ) );
     }
 
     @Test
     public void givenFloatValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( 42F );
+        String serialized = serialization.serialize( 42F );
         System.out.println( serialized );
 
-        Float deserialized = stateSerialization.deserialize( module, Float.class, serialized
);
+        Float deserialized = serialization.deserialize( module, Float.class, serialized );
         assertThat( deserialized, equalTo( 42F ) );
     }
 
     @Test
     public void givenDoubleValueWhenSerializingAndDeserializingExpectEquals()
     {
-        String serialized = stateSerialization.serialize( 42D );
+        String serialized = serialization.serialize( 42D );
         System.out.println( serialized );
 
-        Double deserialized = stateSerialization.deserialize( module, Double.class, serialized
);
+        Double deserialized = serialization.deserialize( module, Double.class, serialized
);
         assertThat( deserialized, equalTo( 42D ) );
     }
 
@@ -217,10 +231,10 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
         BigInteger bigInteger = new BigInteger( "42424242424242424242424242" );
         assertThat( bigInteger, not( equalTo( BigInteger.valueOf( bigInteger.longValue()
) ) ) );
 
-        String serialized = stateSerialization.serialize( bigInteger );
+        String serialized = serialization.serialize( bigInteger );
         System.out.println( serialized );
 
-        BigInteger deserialized = stateSerialization.deserialize( module, BigInteger.class,
serialized );
+        BigInteger deserialized = serialization.deserialize( module, BigInteger.class, serialized
);
         assertThat( deserialized, equalTo( bigInteger ) );
     }
 
@@ -230,10 +244,10 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
         BigDecimal bigDecimal = new BigDecimal( "42.2376931348623157e+309" );
         assertThat( bigDecimal.doubleValue(), equalTo( Double.POSITIVE_INFINITY ) );
 
-        String serialized = stateSerialization.serialize( bigDecimal );
+        String serialized = serialization.serialize( bigDecimal );
         System.out.println( serialized );
 
-        BigDecimal deserialized = stateSerialization.deserialize( module, BigDecimal.class,
serialized );
+        BigDecimal deserialized = serialization.deserialize( module, BigDecimal.class, serialized
);
         assertThat( deserialized, equalTo( bigDecimal ) );
     }
 
@@ -241,45 +255,45 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
     public void givenLocalDateTimeValueWhenSerializingAndDeserializingExpectEquals() throws
Exception
     {
         // Serialized without TimeZone
-        String serialized = stateSerialization.serialize( LocalDateTime.of( 2020, 3, 4, 13,
23, 12 ) );
+        String serialized = serialization.serialize( LocalDateTime.of( 2020, 3, 4, 13, 23,
12 ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "2020-03-04T13:23:12"
) );
 
-        LocalDateTime deserialized = stateSerialization.deserialize( module, LocalDateTime.class,
serialized );
+        LocalDateTime deserialized = serialization.deserialize( module, LocalDateTime.class,
serialized );
         assertThat( deserialized, equalTo( LocalDateTime.of( 2020, 3, 4, 13, 23, 12 ) ) );
     }
 
     @Test
     public void givenLocalDateValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( LocalDate.of( 2020, 3, 4 ) );
+        String serialized = serialization.serialize( LocalDate.of( 2020, 3, 4 ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "2020-03-04" ) );
 
-        LocalDate deserialized = stateSerialization.deserialize( module, LocalDate.class,
serialized );
+        LocalDate deserialized = serialization.deserialize( module, LocalDate.class, serialized
);
         assertThat( deserialized, equalTo( LocalDate.of( 2020, 3, 4 ) ) );
     }
 
     @Test
     public void givenLocalTimeValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( LocalTime.of( 14, 54, 27 ) );
+        String serialized = serialization.serialize( LocalTime.of( 14, 54, 27 ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "14:54:27" ) );
 
-        LocalTime deserialized = stateSerialization.deserialize( module, LocalTime.class,
serialized );
+        LocalTime deserialized = serialization.deserialize( module, LocalTime.class, serialized
);
         assertThat( deserialized, equalTo( LocalTime.of( 14, 54, 27 ) ) );
     }
 
     @Test
     public void givenOffsetDateTimeValueWhenSerializingAndDeserializingExpectEquals() throws
Exception
     {
-        String serialized = stateSerialization.serialize( OffsetDateTime.of( 2009, 8, 12,
14, 54, 27, 895000000,
-                                                                             ZoneOffset.ofHours(
8 ) ) );
+        String serialized = serialization.serialize( OffsetDateTime.of( 2009, 8, 12, 14,
54, 27, 895000000,
+                                                                        ZoneOffset.ofHours(
8 ) ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "2009-08-12T14:54:27.895+08:00"
) );
 
-        OffsetDateTime deserialized = stateSerialization.deserialize( module, OffsetDateTime.class,
serialized );
+        OffsetDateTime deserialized = serialization.deserialize( module, OffsetDateTime.class,
serialized );
         assertThat( deserialized, equalTo( OffsetDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000,
                                                               ZoneOffset.ofHours( 8 ) ) )
);
     }
@@ -287,12 +301,12 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
     @Test
     public void givenZonedDateTimeValueWhenSerializingAndDeserializingExpectEquals() throws
Exception
     {
-        String serialized = stateSerialization.serialize( ZonedDateTime.of( 2009, 8, 12,
14, 54, 27, 895000000,
-                                                                            ZoneId.of( "CET"
) ) );
+        String serialized = serialization.serialize( ZonedDateTime.of( 2009, 8, 12, 14, 54,
27, 895000000,
+                                                                       ZoneId.of( "CET" )
) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "2009-08-12T14:54:27.895+02:00[CET]"
) );
 
-        ZonedDateTime deserialized = stateSerialization.deserialize( module, ZonedDateTime.class,
serialized );
+        ZonedDateTime deserialized = serialization.deserialize( module, ZonedDateTime.class,
serialized );
         assertThat( deserialized, equalTo( ZonedDateTime.of( 2009, 8, 12, 14, 54, 27, 895000000,
                                                              ZoneId.of( "CET" ) ) ) );
     }
@@ -300,50 +314,107 @@ public abstract class AbstractPlainValueSerializationTest extends AbstractPolyge
     @Test
     public void givenInstantValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( Instant.parse( "2016-06-11T08:47:12.620Z"
) );
+        String serialized = serialization.serialize( Instant.parse( "2016-06-11T08:47:12.620Z"
) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "2016-06-11T08:47:12.620Z"
) );
 
-        Instant deserialized = stateSerialization.deserialize( module, Instant.class, serialized
);
+        Instant deserialized = serialization.deserialize( module, Instant.class, serialized
);
         assertThat( deserialized, equalTo( Instant.parse( "2016-06-11T08:47:12.620Z" ) )
);
     }
 
     @Test
     public void givenDurationValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( Duration.ofMillis( 3500 ) );
+        String serialized = serialization.serialize( Duration.ofMillis( 3500 ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "PT3.5S" ) );
 
-        Duration deserialized = stateSerialization.deserialize( module, Duration.class, serialized
);
+        Duration deserialized = serialization.deserialize( module, Duration.class, serialized
);
         assertThat( deserialized, equalTo( Duration.ofMillis( 3500 ) ) );
     }
 
     @Test
     public void givenPeriodValueWhenSerializingAndDeserializingExpectEquals() throws Exception
     {
-        String serialized = stateSerialization.serialize( Period.of( 3, 5, 13 ) );
+        String serialized = serialization.serialize( Period.of( 3, 5, 13 ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "P3Y5M13D" ) );
 
-        Period deserialized = stateSerialization.deserialize( module, Period.class, serialized
);
+        Period deserialized = serialization.deserialize( module, Period.class, serialized
);
         assertThat( deserialized, equalTo( Period.of( 3, 5, 13 ) ) );
     }
 
     @Test
     public void givenEntityReferenceValueWhenSerializingAndDeserializingExpectEquals() throws
Exception
     {
-        String serialized = stateSerialization.serialize( EntityReference.parseEntityReference(
"ABCD-1234" ) );
+        String serialized = serialization.serialize( EntityReference.parseEntityReference(
"ABCD-1234" ) );
         System.out.println( serialized );
         assertThat( getSingleStringRawState( serialized ), equalTo( "ABCD-1234" ) );
 
-        EntityReference deserialized = stateSerialization.deserialize( module, EntityReference.class,
serialized );
+        EntityReference deserialized = serialization.deserialize( module, EntityReference.class,
serialized );
         assertThat( deserialized, equalTo( EntityReference.parseEntityReference( "ABCD-1234"
) ) );
     }
 
+    @Test
+    public void givenCustomPlainValueTypeAndItsConverterWhenSerializingAndDeserializingExpectEquals()
throws Exception
+    {
+        String serialized = serialization.serialize( new CustomConvertedValue( "ABCD-1234"
) );
+        System.out.println( serialized );
+        assertThat( getSingleStringRawState( serialized ), equalTo( "ABCD-1234" ) );
+
+        CustomConvertedValue deserialized = serialization.deserialize( module, CustomConvertedValue.class,
serialized );
+        assertThat( deserialized, equalTo( new CustomConvertedValue( "ABCD-1234" ) ) );
+    }
+
     private enum SomeEnum
     {
         BÆR,
         BAZAR
     }
+
+    static class CustomConverter implements Converter<CustomConvertedValue>
+    {
+        @Override
+        public Class<CustomConvertedValue> type()
+        {
+            return CustomConvertedValue.class;
+        }
+
+        @Override
+        public String toString( CustomConvertedValue object )
+        {
+            return object.value;
+        }
+
+        @Override
+        public CustomConvertedValue fromString( String string )
+        {
+            return new CustomConvertedValue( string );
+        }
+    }
+
+    static class CustomConvertedValue
+    {
+        private final String value;
+
+        CustomConvertedValue( String value )
+        {
+            this.value = value;
+        }
+
+        @Override
+        public boolean equals( final Object o )
+        {
+            if( this == o ) { return true; }
+            if( o == null || getClass() != o.getClass() ) { return false; }
+            CustomConvertedValue that = (CustomConvertedValue) o;
+            return Objects.equals( value, that.value );
+        }
+
+        @Override
+        public int hashCode()
+        {
+            return Objects.hashCode( value );
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
b/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
index 8be807f..887c555 100644
--- a/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
+++ b/extensions/serialization-javaxjson/src/test/java/org/apache/polygene/serialization/javaxjson/JavaxJsonPlainValueSerializationTest.java
@@ -19,11 +19,20 @@
  */
 package org.apache.polygene.serialization.javaxjson;
 
+import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.test.serialization.AbstractPlainValueSerializationTest;
 
 public class JavaxJsonPlainValueSerializationTest extends AbstractPlainValueSerializationTest
 {
     @Override
+    public void assemble( final ModuleAssembly module )
+    {
+        new JavaxJsonSerializationAssembler()
+            .withJsonSettings( withTestSettings( new JavaxJsonSettings() ) )
+            .assemble( module );
+    }
+
+    @Override
     protected String getSingleStringRawState( String state )
     {
         return state;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
index 10b692e..a50f0f2 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializationService.java
@@ -54,10 +54,9 @@ public interface JavaxXmlSerializationService extends JavaxXmlSerialization,
Ser
         {
             if( !registrationDone )
             {
-                registerCustomConverters();
+                applySettings();
                 registerBuiltInConverters();
-                registerCustomAdapters();
-                registerBaseAdapters();
+                registerBaseJavaxXmlAdapters();
                 registrationDone = true;
             }
         }
@@ -65,9 +64,14 @@ public interface JavaxXmlSerializationService extends JavaxXmlSerialization,
Ser
         @Override
         public void passivateService() {}
 
-        private void registerCustomConverters()
+        private void applySettings()
         {
-            // TODO register custom converters
+            JavaxXmlSettings settings
+                = JavaxXmlSettings.orDefault( descriptor.metaInfo( JavaxXmlSettings.class
) );
+            settings.getConverters()
+                    .forEach( ( type, converter ) -> converters.registerConverter( type,
converter ) );
+            settings.getAdapters()
+                    .forEach( ( type, adapter ) -> adapters.registerAdapter( type, adapter
) );
         }
 
         private void registerBuiltInConverters()
@@ -75,14 +79,7 @@ public interface JavaxXmlSerializationService extends JavaxXmlSerialization,
Ser
             builtInConverters.registerBuiltInConverters( converters );
         }
 
-        private void registerCustomAdapters()
-        {
-            JavaxXmlSettings.orDefault( descriptor.metaInfo( JavaxXmlSettings.class ) )
-                            .getAdapters()
-                            .forEach( ( valueType, adapter ) -> adapters.registerAdapter(
valueType, adapter ) );
-        }
-
-        private void registerBaseAdapters()
+        private void registerBaseJavaxXmlAdapters()
         {
             // Primitive Value types
             adapters.registerAdapter( ValueType.STRING, new StringAdapter() );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
index 775f941..c5484fb 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSettings.java
@@ -20,6 +20,7 @@ package org.apache.polygene.serialization.javaxxml;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.serialization.SerializationSettings;
 
 /**
  * javax.xml settings.
@@ -27,7 +28,7 @@ import org.apache.polygene.api.type.ValueType;
  * Must be registered as meta-info at assembly time.
  */
 // TODO javax.xml properties?
-public class JavaxXmlSettings
+public class JavaxXmlSettings extends SerializationSettings<JavaxXmlSettings>
 {
     public static final JavaxXmlSettings DEFAULT = new JavaxXmlSettings();
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
index 11979a2..4d0b07e 100644
--- a/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
+++ b/extensions/serialization-javaxxml/src/test/java/org/apache/polygene/serialization/javaxxml/JavaxXmlPlainValueSerializationTest.java
@@ -35,8 +35,8 @@ public class JavaxXmlPlainValueSerializationTest extends AbstractPlainValueSeria
     @Override
     public void assemble( ModuleAssembly module )
     {
-        new JavaxXmlSerializationAssembler().assemble( module );
-        super.assemble( module );
+        new JavaxXmlSerializationAssembler().withXmlSettings( withTestSettings( new JavaxXmlSettings()
) )
+                                            .assemble( module );
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
index 51badc3..9bc2d74 100644
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
+++ b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializationService.java
@@ -54,10 +54,9 @@ public interface MessagePackSerializationService extends MessagePackSerializatio
         {
             if( !registrationDone )
             {
-                registerCustomConverters();
+                applySettings();
                 registerBuiltInConverters();
-                registerCustomAdapters();
-                registerBaseAdapters();
+                registerBaseMessagePackAdapters();
                 registrationDone = true;
             }
         }
@@ -65,9 +64,14 @@ public interface MessagePackSerializationService extends MessagePackSerializatio
         @Override
         public void passivateService() {}
 
-        private void registerCustomConverters()
+        private void applySettings()
         {
-            // TODO register custom converters
+            MessagePackSettings settings
+                = MessagePackSettings.orDefault( descriptor.metaInfo( MessagePackSettings.class
) );
+            settings.getConverters()
+                    .forEach( ( type, converter ) -> converters.registerConverter( type,
converter ) );
+            settings.getAdapters()
+                    .forEach( ( type, adapter ) -> adapters.registerAdapter( type, adapter
) );
         }
 
         private void registerBuiltInConverters()
@@ -75,14 +79,7 @@ public interface MessagePackSerializationService extends MessagePackSerializatio
             builtInConverters.registerBuiltInConverters( converters );
         }
 
-        private void registerCustomAdapters()
-        {
-            MessagePackSettings.orDefault( descriptor.metaInfo( MessagePackSettings.class
) )
-                               .getAdapters()
-                               .forEach( ( valueType, adapter ) -> adapters.registerAdapter(
valueType, adapter ) );
-        }
-
-        private void registerBaseAdapters()
+        private void registerBaseMessagePackAdapters()
         {
             // Primitive Value types
             adapters.registerAdapter( ValueType.STRING, new StringAdapter() );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSettings.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSettings.java
b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSettings.java
index 8080d94..e3fbf26 100644
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSettings.java
+++ b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSettings.java
@@ -20,8 +20,9 @@ package org.apache.polygene.serialization.msgpack;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import org.apache.polygene.api.type.ValueType;
+import org.apache.polygene.spi.serialization.SerializationSettings;
 
-public class MessagePackSettings
+public class MessagePackSettings extends SerializationSettings<MessagePackSettings>
 {
     public static final MessagePackSettings DEFAULT = new MessagePackSettings();
 

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/d3ec800f/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
b/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
index 48ad8f8..6714527 100644
--- a/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
+++ b/extensions/serialization-msgpack/src/test/java/org/apache/polygene/serialization/msgpack/MessagePackPlainValueSerializationTest.java
@@ -29,8 +29,8 @@ public class MessagePackPlainValueSerializationTest extends AbstractPlainValueSe
     @Override
     public void assemble( ModuleAssembly module )
     {
-        new MessagePackSerializationAssembler().assemble( module );
-        super.assemble( module );
+        new MessagePackSerializationAssembler().withMessagePackSettings( withTestSettings(
new MessagePackSettings() ) )
+                                               .assemble( module );
     }
 
     @Override


Mime
View raw message