polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [1/7] polygene-java git commit: POLYGENE-247 Change Entity state JSON serialization format
Date Sun, 23 Apr 2017 11:07:31 GMT
Repository: polygene-java
Updated Branches:
  refs/heads/develop 718fa57ca -> 53ae77b73


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/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 507eb6a..c0ad355 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
@@ -33,6 +33,8 @@ import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Stream;
 import org.apache.polygene.api.association.AssociationDescriptor;
+import org.apache.polygene.api.composite.CompositeDescriptor;
+import org.apache.polygene.api.composite.StatefulAssociationCompositeDescriptor;
 import org.apache.polygene.api.entity.EntityReference;
 import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.mixin.Mixins;
@@ -47,11 +49,10 @@ import org.apache.polygene.api.type.ArrayType;
 import org.apache.polygene.api.type.CollectionType;
 import org.apache.polygene.api.type.EnumType;
 import org.apache.polygene.api.type.MapType;
-import org.apache.polygene.api.type.ValueCompositeType;
+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.api.value.ValueDescriptor;
 import org.apache.polygene.spi.serialization.AbstractBinaryDeserializer;
 import org.msgpack.core.MessagePack;
 import org.msgpack.core.MessageUnpacker;
@@ -79,8 +80,7 @@ public interface MessagePackDeserializer extends Deserializer
         @Override
         public <T> T deserialize( ModuleDescriptor module, ValueType valueType, InputStream
state )
         {
-            MessageUnpacker unpacker = MessagePack.newDefaultUnpacker( state );
-            try
+            try( MessageUnpacker unpacker = MessagePack.newDefaultUnpacker( state ) )
             {
                 if( !unpacker.hasNext() )
                 {
@@ -89,9 +89,9 @@ public interface MessagePackDeserializer extends Deserializer
                 ImmutableValue value = unpacker.unpackValue();
                 return doDeserialize( module, valueType, value );
             }
-            catch( IOException e )
+            catch( IOException ex )
             {
-                throw new SerializationException( "Unable to deserialize " + valueType );
+                throw new SerializationException( "Unable to deserialize " + valueType, ex
);
             }
         }
 
@@ -120,25 +120,28 @@ public interface MessagePackDeserializer extends Deserializer
                 {
                     return (T) adapter.deserialize( value, ( val, type ) -> doDeserialize(
module, valueType, val ) );
                 }
-                if( EnumType.class.isAssignableFrom( valueType.getClass() ) )
+                Class<? extends ValueType> valueTypeClass = valueType.getClass();
+                if( EnumType.class.isAssignableFrom( valueTypeClass ) )
                 {
                     return (T) Enum.valueOf( (Class) valueType.primaryType(), value.asStringValue().asString()
);
                 }
-                if( ArrayType.class.isAssignableFrom( valueType.getClass() ) )
+                if( ArrayType.class.isAssignableFrom( valueTypeClass ) )
                 {
                     return (T) deserializeArray( module, (ArrayType) valueType, value );
                 }
-                if( CollectionType.class.isAssignableFrom( valueType.getClass() ) )
+                if( CollectionType.class.isAssignableFrom( valueTypeClass ) )
                 {
                     return (T) deserializeCollection( module, (CollectionType) valueType,
value.asArrayValue() );
                 }
-                if( MapType.class.isAssignableFrom( valueType.getClass() ) )
+                if( MapType.class.isAssignableFrom( valueTypeClass ) )
                 {
                     return (T) deserializeMap( module, (MapType) valueType, value.asMapValue()
);
                 }
-                if( ValueCompositeType.class.isAssignableFrom( valueType.getClass() ) )
+                if( StatefulAssociationValueType.class.isAssignableFrom( valueTypeClass )
)
                 {
-                    return (T) deserializeValueComposite( module, (ValueCompositeType) valueType,
value.asMapValue() );
+                    return (T) deserializeStatefulAssociationValue( module,
+                                                                    (StatefulAssociationValueType<?>)
valueType,
+                                                                    value.asMapValue() );
                 }
                 return (T) doGuessDeserialize( module, valueType, value );
             }
@@ -189,8 +192,9 @@ public interface MessagePackDeserializer extends Deserializer
             return map;
         }
 
-        private Object deserializeValueComposite( ModuleDescriptor module, ValueCompositeType
valueType,
-                                                  MapValue value ) throws IOException
+        private Object deserializeStatefulAssociationValue( ModuleDescriptor module,
+                                                            StatefulAssociationValueType<?>
valueType,
+                                                            MapValue value ) throws IOException
         {
             Map<String, Value> namedValues = value.map().entrySet().stream().map(
                 entry ->
@@ -207,7 +211,8 @@ public interface MessagePackDeserializer extends Deserializer
             }
             if( typeInfo != null )
             {
-                ValueDescriptor descriptor = module.valueDescriptor( typeInfo );
+                // TODO What to do with typeInfo? Value or Entity ?
+                StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor(
module, typeInfo );
                 if( descriptor == null )
                 {
                     throw new SerializationException(
@@ -299,17 +304,6 @@ public interface MessagePackDeserializer extends Deserializer
         {
             switch( value.getValueType() )
             {
-                case BINARY:
-                    try
-                    {
-                        return deserializeJava( value.asBinaryValue().asByteArray() );
-                    }
-                    catch( SerializationException ex )
-                    {
-                        throw new SerializationException( "Don't know how to deserialize
" + valueType
-                                                          + " from " + value + " (" + value.getValueType()
+ ")",
-                                                          ex );
-                    }
                 case MAP:
                     MapValue mapValue = value.asMapValue();
                     Optional<String> typeInfo = mapValue
@@ -325,12 +319,13 @@ public interface MessagePackDeserializer extends Deserializer
                         .map( entry -> doDeserialize( module, ValueType.STRING, entry.getValue()
) );
                     if( typeInfo.isPresent() )
                     {
-                        ValueDescriptor valueDescriptor = module.valueDescriptor( typeInfo.get()
);
-                        if( valueDescriptor != null )
+                        StatefulAssociationCompositeDescriptor descriptor = statefulCompositeDescriptorFor(
+                            module, typeInfo.get() );
+                        if( descriptor != null )
                         {
-                            return deserializeValueComposite( valueDescriptor.module(),
-                                                              valueDescriptor.valueType(),
-                                                              mapValue );
+                            return deserializeStatefulAssociationValue( ( (CompositeDescriptor)
descriptor ).module(),
+                                                                        descriptor.valueType(),
+                                                                        mapValue );
                         }
                     }
                 default:

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/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 dea03e1..9e539bf 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
@@ -25,7 +25,9 @@ import java.util.stream.StreamSupport;
 import org.apache.polygene.api.PolygeneAPI;
 import org.apache.polygene.api.association.AssociationStateHolder;
 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;
@@ -38,10 +40,7 @@ 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;
-import org.apache.polygene.api.type.ValueCompositeType;
-import org.apache.polygene.api.util.Annotations;
-import org.apache.polygene.api.value.ValueComposite;
-import org.apache.polygene.api.value.ValueDescriptor;
+import org.apache.polygene.api.type.StatefulAssociationValueType;
 import org.apache.polygene.spi.serialization.AbstractBinarySerializer;
 import org.apache.polygene.spi.util.ArrayIterable;
 import org.msgpack.core.MessagePack;
@@ -71,10 +70,9 @@ public interface MessagePackSerializer extends Serializer
         @Override
         public void serialize( Options options, OutputStream output, @Optional Object object
)
         {
-            MessagePacker packer = MessagePack.newDefaultPacker( output );
-            Value value = doSerialize( options, object, true );
-            try
+            try( MessagePacker packer = MessagePack.newDefaultPacker( output ) )
             {
+                Value value = doSerialize( options, object, true );
                 packer.packValue( value );
                 packer.flush();
             }
@@ -93,11 +91,6 @@ public interface MessagePackSerializer extends Serializer
                     return ValueFactory.newNil();
                 }
                 Class<?> objectClass = object.getClass();
-                ConvertedBy convertedBy = Annotations.annotationOn( objectClass, ConvertedBy.class
);
-                if( convertedBy != null )
-                {
-                    return doSerialize( options, module.newObject( convertedBy.value() ).toString(
object ), false );
-                }
                 Converter<Object> converter = converters.converterFor( objectClass
);
                 if( converter != null )
                 {
@@ -112,9 +105,9 @@ public interface MessagePackSerializer extends Serializer
                 {
                     return ValueFactory.newString( object.toString() );
                 }
-                if( ValueCompositeType.isValueComposite( objectClass ) )
+                if( StatefulAssociationValueType.isStatefulAssociationValue( objectClass
) )
                 {
-                    return serializeValueComposite( options, object, root );
+                    return serializeStatefulAssociationValue( options, object, root );
                 }
                 if( MapType.isMap( objectClass ) )
                 {
@@ -132,8 +125,7 @@ public interface MessagePackSerializer extends Serializer
                 {
                     return serializeStream( options, (Stream<?>) object );
                 }
-                // Fallback to Java Serialization
-                return ValueFactory.newBinary( serializeJava( object ) );
+                throw new SerializationException( "Don't know how to serialize " + object
);
             }
             catch( IOException ex )
             {
@@ -141,12 +133,13 @@ public interface MessagePackSerializer extends Serializer
             }
         }
 
-        private MapValue serializeValueComposite( Options options, Object composite, boolean
root )
+        private MapValue serializeStatefulAssociationValue( Options options, Object composite,
boolean root )
         {
-            CompositeInstance instance = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply(
(ValueComposite) composite );
-            ValueDescriptor descriptor = (ValueDescriptor) instance.descriptor();
+            CompositeInstance instance = PolygeneAPI.FUNCTION_COMPOSITE_INSTANCE_OF.apply(
(Composite) composite );
+            StatefulAssociationCompositeDescriptor descriptor =
+                (StatefulAssociationCompositeDescriptor) instance.descriptor();
             AssociationStateHolder state = (AssociationStateHolder) instance.state();
-            ValueCompositeType valueType = descriptor.valueType();
+            StatefulAssociationValueType<?> valueType = descriptor.valueType();
 
             ValueFactory.MapBuilder builder = ValueFactory.newMapBuilder();
             valueType.properties().forEach(
@@ -179,7 +172,7 @@ public interface MessagePackSerializer extends Serializer
                                  state.namedAssociationFor( association.accessor() ).references().collect(
toMap() ),
                                  false ) ) );
 
-            if( !root && options.includeTypeInfo() )
+            if( ( root && options.rootTypeInfo() ) || ( !root && options.nestedTypeInfo()
) )
             {
                 builder.put( ValueFactory.newString( "_type" ),
                              ValueFactory.newString( valueType.primaryType().getName() )
);

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/assembly/MessagePackSerializationAssembler.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/assembly/MessagePackSerializationAssembler.java
b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/assembly/MessagePackSerializationAssembler.java
index 6bb7a1e..7f87458 100644
--- a/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/assembly/MessagePackSerializationAssembler.java
+++ b/extensions/serialization-messagepack/src/main/java/org/apache/polygene/serialization/messagepack/assembly/MessagePackSerializationAssembler.java
@@ -17,12 +17,14 @@
  */
 package org.apache.polygene.serialization.messagepack.assembly;
 
+import org.apache.polygene.api.serialization.Converters;
 import org.apache.polygene.api.serialization.Deserializer;
 import org.apache.polygene.api.serialization.Serialization;
 import org.apache.polygene.api.serialization.Serializer;
 import org.apache.polygene.bootstrap.Assemblers;
 import org.apache.polygene.bootstrap.ModuleAssembly;
 import org.apache.polygene.bootstrap.ServiceDeclaration;
+import org.apache.polygene.serialization.messagepack.MessagePackAdapters;
 import org.apache.polygene.serialization.messagepack.MessagePackSerialization;
 import org.apache.polygene.serialization.messagepack.MessagePackSettings;
 
@@ -40,7 +42,10 @@ public class MessagePackSerializationAssembler extends Assemblers.VisibilityIden
     public void assemble( ModuleAssembly module )
     {
         ServiceDeclaration declaration = module.services( MessagePackSerialization.class
)
-                                               .withTypes( Serialization.class, Serializer.class,
Deserializer.class )
+                                               .withTypes( Serialization.class,
+                                                           Serializer.class, Deserializer.class,
+                                                           Converters.class,
+                                                           MessagePackAdapters.class )
                                                .visibleIn( visibility() );
         if( hasIdentity() )
         {

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/JSONResponseReader.java
----------------------------------------------------------------------
diff --git a/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/JSONResponseReader.java
b/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/JSONResponseReader.java
index 335c26b..2090357 100644
--- a/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/JSONResponseReader.java
+++ b/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/JSONResponseReader.java
@@ -21,9 +21,9 @@
 package org.apache.polygene.library.rest.client.responsereader;
 
 import java.io.IOException;
-import javax.json.Json;
 import javax.json.JsonException;
 import javax.json.JsonObject;
+import javax.json.JsonReader;
 import javax.json.JsonString;
 import javax.json.JsonValue;
 import org.apache.polygene.api.injection.scope.Service;
@@ -32,6 +32,7 @@ import org.apache.polygene.api.structure.ModuleDescriptor;
 import org.apache.polygene.api.type.ValueCompositeType;
 import org.apache.polygene.api.value.ValueComposite;
 import org.apache.polygene.library.rest.client.spi.ResponseReader;
+import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories;
 import org.apache.polygene.spi.serialization.JsonDeserializer;
 import org.restlet.Response;
 import org.restlet.data.Form;
@@ -50,6 +51,9 @@ public class JSONResponseReader
     @Service
     private JsonDeserializer jsonDeserializer;
 
+    @Service
+    private JavaxJsonFactories jsonFactories;
+
     @Override
     public Object readResponse( Response response, Class<?> resultType )
     {
@@ -63,14 +67,14 @@ public class JSONResponseReader
             }
             else if( resultType.equals( Form.class ) )
             {
-                try
+                try( JsonReader reader = jsonFactories.readerFactory()
+                                                      .createReader( response.getEntity().getReader()
) )
                 {
-                    JsonObject jsonObject = Json.createReader( response.getEntity().getReader()
).readObject();
+                    JsonObject jsonObject = reader.readObject();
                     Form form = new Form();
                     jsonObject.entrySet().forEach(
                         entry ->
                         {
-
                             String key = entry.getKey();
                             JsonValue value = entry.getValue();
                             String valueString = value.getValueType() == JsonValue.ValueType.STRING

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/TableResponseReader.java
----------------------------------------------------------------------
diff --git a/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/TableResponseReader.java
b/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/TableResponseReader.java
index 55019a3..7d9cb36 100644
--- a/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/TableResponseReader.java
+++ b/libraries/rest-client/src/main/java/org/apache/polygene/library/rest/client/responsereader/TableResponseReader.java
@@ -23,9 +23,9 @@ package org.apache.polygene.library.rest.client.responsereader;
 import java.time.ZonedDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
-import javax.json.Json;
 import javax.json.JsonArray;
 import javax.json.JsonObject;
+import javax.json.JsonReader;
 import javax.json.JsonString;
 import javax.json.JsonValue;
 import org.apache.polygene.api.injection.scope.Service;
@@ -34,6 +34,7 @@ import org.apache.polygene.api.structure.Module;
 import org.apache.polygene.library.rest.client.spi.ResponseReader;
 import org.apache.polygene.library.rest.common.table.Table;
 import org.apache.polygene.library.rest.common.table.TableBuilder;
+import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories;
 import org.apache.polygene.spi.serialization.JsonDeserializer;
 import org.restlet.Response;
 import org.restlet.data.MediaType;
@@ -52,15 +53,19 @@ public class TableResponseReader
     @Service
     private JsonDeserializer jsonDeserializer;
 
+    @Service
+    private JavaxJsonFactories jsonFactories;
+
     @Override
     public Object readResponse( Response response, Class<?> resultType ) throws ResourceException
     {
         if( response.getEntity().getMediaType().equals( MediaType.APPLICATION_JSON )
             && Table.class.isAssignableFrom( resultType ) )
         {
-            try
+            try( JsonReader reader = jsonFactories.readerFactory()
+                                                  .createReader( response.getEntity().getReader()
) )
             {
-                JsonObject jsonObject = Json.createReader( response.getEntity().getReader()
).readObject();
+                JsonObject jsonObject = reader.readObject();
                 JsonObject table = jsonObject.getJsonObject( "table" );
 
                 TableBuilder builder = new TableBuilder( module );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/api/ContextResource.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/api/ContextResource.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/api/ContextResource.java
index 25cb0df..4b701fb 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/api/ContextResource.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/api/ContextResource.java
@@ -42,6 +42,7 @@ import org.apache.polygene.api.identity.Identity;
 import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.injection.scope.Uses;
+import org.apache.polygene.api.serialization.Serializer;
 import org.apache.polygene.api.structure.Module;
 import org.apache.polygene.api.unitofwork.NoSuchEntityException;
 import org.apache.polygene.api.unitofwork.NoSuchEntityTypeException;
@@ -109,6 +110,9 @@ public class ContextResource
     @Service
     private InteractionConstraints constraints;
 
+    @Service
+    private Serializer serializer;
+
     @Optional
     @Service
     private ResultConverter converter;
@@ -883,7 +887,7 @@ public class ContextResource
                     Object initialValue = propertyDescriptor.resolveInitialValue(module.descriptor());
                     if( initialValue != null )
                     {
-                        value = initialValue.toString();
+                        value = serializer.serialize( initialValue );
                     }
                 }
                 form.add( propertyDescriptor.qualifiedName().name(), value );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/requestreader/DefaultRequestReader.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/requestreader/DefaultRequestReader.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/requestreader/DefaultRequestReader.java
index eea0994..b968da4 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/requestreader/DefaultRequestReader.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/requestreader/DefaultRequestReader.java
@@ -40,9 +40,6 @@ import org.apache.polygene.api.identity.StringIdentity;
 import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.property.PropertyDescriptor;
-import org.apache.polygene.api.service.qualifier.Tagged;
-import org.apache.polygene.api.serialization.Deserializer;
-import org.apache.polygene.api.serialization.Serialization;
 import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.structure.ModuleDescriptor;
 import org.apache.polygene.api.unitofwork.UnitOfWorkFactory;
@@ -50,6 +47,7 @@ import org.apache.polygene.api.value.ValueBuilder;
 import org.apache.polygene.api.value.ValueBuilderFactory;
 import org.apache.polygene.api.value.ValueComposite;
 import org.apache.polygene.library.rest.server.spi.RequestReader;
+import org.apache.polygene.spi.serialization.JsonDeserializer;
 import org.restlet.Request;
 import org.restlet.Response;
 import org.restlet.data.CharacterSet;
@@ -86,8 +84,7 @@ public class DefaultRequestReader
     private ValueBuilderFactory vbf;
 
     @Service
-    @Tagged( Serialization.Format.JSON )
-    private Deserializer deserializer;
+    private JsonDeserializer deserializer;
 
     @Override
     @SuppressWarnings( "unchecked" )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/FormResponseWriter.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/FormResponseWriter.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/FormResponseWriter.java
index f59d166..9535e43 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/FormResponseWriter.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/FormResponseWriter.java
@@ -29,11 +29,11 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.json.Json;
 import javax.json.JsonException;
 import javax.json.JsonObjectBuilder;
 import javax.json.JsonValue;
 import org.apache.polygene.api.injection.scope.Service;
+import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories;
 import org.restlet.Response;
 import org.restlet.data.Form;
 import org.restlet.data.MediaType;
@@ -55,6 +55,9 @@ public class FormResponseWriter
     @Service
     private Configuration cfg;
 
+    @Service
+    private JavaxJsonFactories jsonFactories;
+
     @Override
     public boolean writeResponse( final Object result, final Response response )
         throws ResourceException
@@ -64,7 +67,7 @@ public class FormResponseWriter
             MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes
).getMediaType();
             if( MediaType.APPLICATION_JSON.equals( type ) )
             {
-                JsonObjectBuilder builder = Json.createObjectBuilder();
+                JsonObjectBuilder builder = jsonFactories.builderFactory().createObjectBuilder();
                 Form form = (Form) result;
                 try
                 {
@@ -100,7 +103,7 @@ public class FormResponseWriter
                     public void write( Writer writer )
                         throws IOException
                     {
-                        Map<String, Object> root = new HashMap<String, Object>();
+                        Map<String, Object> root = new HashMap<>();
                         root.put( "request", response.getRequest() );
                         root.put( "response", response );
                         root.put( "result", result );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/LinksResponseWriter.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/LinksResponseWriter.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/LinksResponseWriter.java
index dcac1db..522eae1 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/LinksResponseWriter.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/LinksResponseWriter.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.library.rest.common.link.Link;
 import org.apache.polygene.library.rest.common.link.Links;
+import org.apache.polygene.spi.serialization.JsonSerializer;
 import org.restlet.Response;
 import org.restlet.data.MediaType;
 import org.restlet.data.Reference;
@@ -53,6 +54,9 @@ public class LinksResponseWriter
     @Service
     Configuration cfg;
 
+    @Service
+    JsonSerializer jsonSerializer;
+
     @Override
     public boolean writeResponse( final Object result, final Response response )
         throws ResourceException
@@ -62,7 +66,8 @@ public class LinksResponseWriter
             MediaType type = getVariant( response.getRequest(), ENGLISH, supportedLinkMediaTypes
).getMediaType();
             if( MediaType.APPLICATION_JSON.equals( type ) )
             {
-                response.setEntity( new StringRepresentation( result.toString(), MediaType.APPLICATION_JSON
) );
+                String json = jsonSerializer.serialize( result );
+                response.setEntity( new StringRepresentation( json, MediaType.APPLICATION_JSON
) );
                 return true;
             }
             else
@@ -102,7 +107,8 @@ public class LinksResponseWriter
 
     private StringRepresentation createJsonRepresentation( Links result )
     {
-        return new StringRepresentation( result.toString(), MediaType.APPLICATION_JSON );
+        String json = jsonSerializer.serialize( result );
+        return new StringRepresentation( json, MediaType.APPLICATION_JSON );
     }
 
     private Representation createTextHtmlRepresentation( final Object result, final Response
response )
@@ -113,7 +119,7 @@ public class LinksResponseWriter
                         public void write( Writer writer )
                             throws IOException
                         {
-                            Map<String, Object> context = new HashMap<String, Object>();
+                            Map<String, Object> context = new HashMap<>();
                             context.put( "request", response.getRequest() );
                             context.put( "response", response );
                             context.put( "result", result );
@@ -137,7 +143,7 @@ public class LinksResponseWriter
             public void write( Writer writer )
                 throws IOException
             {
-                Map<String, Object> context = new HashMap<String, Object>();
+                Map<String, Object> context = new HashMap<>();
                 context.put( "request", response.getRequest() );
                 context.put( "response", response );
                 context.put( "result", result );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ResourceResponseWriter.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ResourceResponseWriter.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ResourceResponseWriter.java
index 4dd0a30..4a913cc 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ResourceResponseWriter.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ResourceResponseWriter.java
@@ -31,6 +31,7 @@ import java.util.Map;
 import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.library.rest.common.Resource;
 import org.apache.polygene.library.rest.common.link.LinksUtil;
+import org.apache.polygene.spi.serialization.JsonSerializer;
 import org.restlet.Response;
 import org.restlet.data.MediaType;
 import org.restlet.data.Method;
@@ -49,6 +50,9 @@ public class ResourceResponseWriter extends AbstractResponseWriter
     @Service
     private Configuration cfg;
 
+    @Service
+    private JsonSerializer jsonSerializer;
+
     @Override
     public boolean writeResponse( final Object result, final Response response )
         throws ResourceException
@@ -72,7 +76,8 @@ public class ResourceResponseWriter extends AbstractResponseWriter
             MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes
).getMediaType();
             if( MediaType.APPLICATION_JSON.equals( type ) )
             {
-                response.setEntity( new StringRepresentation( resourceValue.toString(), MediaType.APPLICATION_JSON
) );
+                String json = jsonSerializer.serialize( resourceValue );
+                response.setEntity( new StringRepresentation( json, MediaType.APPLICATION_JSON
) );
                 return true;
             }
             else if( MediaType.TEXT_HTML.equals( type ) )
@@ -83,7 +88,7 @@ public class ResourceResponseWriter extends AbstractResponseWriter
                     public void write( Writer writer )
                         throws IOException
                     {
-                        Map<String, Object> context = new HashMap<String, Object>();
+                        Map<String, Object> context = new HashMap<>();
                         context.put( "request", response.getRequest() );
                         context.put( "response", response );
                         context.put( "result", result );

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java
index bbe758c..d8d35aa 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/TableResponseWriter.java
@@ -28,17 +28,17 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.json.Json;
 import javax.json.JsonArrayBuilder;
+import javax.json.JsonBuilderFactory;
 import javax.json.JsonException;
 import javax.json.JsonObjectBuilder;
 import org.apache.polygene.api.injection.scope.Service;
-import org.apache.polygene.api.injection.scope.Structure;
-import org.apache.polygene.api.structure.ModuleDescriptor;
+import org.apache.polygene.api.serialization.Serializer;
 import org.apache.polygene.library.rest.common.table.Cell;
 import org.apache.polygene.library.rest.common.table.Column;
 import org.apache.polygene.library.rest.common.table.Row;
 import org.apache.polygene.library.rest.common.table.Table;
+import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories;
 import org.apache.polygene.spi.serialization.JsonSerializer;
 import org.restlet.Response;
 import org.restlet.data.CharacterSet;
@@ -55,13 +55,13 @@ public class TableResponseWriter extends AbstractResponseWriter
     private static final List<MediaType> supportedMediaTypes = Arrays.asList( MediaType.TEXT_HTML,
                                                                               MediaType.APPLICATION_JSON
);
 
-    @Structure
-    private ModuleDescriptor module;
-
     @Service
     private JsonSerializer jsonSerializer;
 
     @Service
+    private JavaxJsonFactories json;
+
+    @Service
     private Configuration cfg;
 
     @Override
@@ -81,7 +81,8 @@ public class TableResponseWriter extends AbstractResponseWriter
                     {
                         try
                         {
-                            JsonObjectBuilder builder = Json.createObjectBuilder();
+                            JsonBuilderFactory jsonBuilderFactory = json.builderFactory();
+                            JsonObjectBuilder builder = jsonBuilderFactory.createObjectBuilder();
                             Table tableValue = (Table) result;
 
                             // Parse parameters
@@ -111,23 +112,23 @@ public class TableResponseWriter extends AbstractResponseWriter
                             }
                             builder.add( "status", "ok" );
 
-                            JsonObjectBuilder tableBuilder = Json.createObjectBuilder();
-                            JsonArrayBuilder colsBuilder = Json.createArrayBuilder();
+                            JsonObjectBuilder tableBuilder = jsonBuilderFactory.createObjectBuilder();
+                            JsonArrayBuilder colsBuilder = jsonBuilderFactory.createArrayBuilder();
                             List<Column> columnList = tableValue.cols().get();
                             for( Column columnValue : columnList )
                             {
-                                colsBuilder.add( Json.createObjectBuilder()
-                                                     .add( "id", columnValue.id().get() )
-                                                     .add( "label", columnValue.label().get()
)
-                                                     .add( "type", columnValue.columnType().get()
)
-                                                     .build() );
+                                colsBuilder.add( jsonBuilderFactory.createObjectBuilder()
+                                                                   .add( "id", columnValue.id().get()
)
+                                                                   .add( "label", columnValue.label().get()
)
+                                                                   .add( "type", columnValue.columnType().get()
)
+                                                                   .build() );
                             }
                             tableBuilder.add( "cols", colsBuilder.build() );
 
-                            JsonArrayBuilder rowsBuilder = Json.createArrayBuilder();
+                            JsonArrayBuilder rowsBuilder = jsonBuilderFactory.createArrayBuilder();
                             for( Row rowValue : tableValue.rows().get() )
                             {
-                                JsonArrayBuilder cellsBuilder = Json.createArrayBuilder();
+                                JsonArrayBuilder cellsBuilder = jsonBuilderFactory.createArrayBuilder();
                                 int idx = 0;
                                 for( Cell cellValue : rowValue.c().get() )
                                 {
@@ -148,10 +149,10 @@ public class TableResponseWriter extends AbstractResponseWriter
                                         value = value.toString();
                                     }
 
-                                    JsonObjectBuilder cellBuilder = Json.createObjectBuilder();
+                                    JsonObjectBuilder cellBuilder = jsonBuilderFactory.createObjectBuilder();
                                     if( value != null )
                                     {
-                                        cellBuilder.add( "v", jsonSerializer.toJson( value
) );
+                                        cellBuilder.add( "v", jsonSerializer.toJson( Serializer.Options.ALL_TYPE_INFO,
value ) );
                                     }
                                     if( cellValue.f().get() != null )
                                     {
@@ -160,7 +161,7 @@ public class TableResponseWriter extends AbstractResponseWriter
                                     cellsBuilder.add( cellBuilder.build() );
                                     idx++;
                                 }
-                                JsonObjectBuilder rowBuilder = Json.createObjectBuilder();
+                                JsonObjectBuilder rowBuilder = jsonBuilderFactory.createObjectBuilder();
                                 rowBuilder.add( "c", cellsBuilder.build() );
                                 rowsBuilder.add( rowBuilder.build() );
                             }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java
index 5d8685d..845b256 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueCompositeResponseWriter.java
@@ -31,10 +31,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import org.apache.polygene.api.injection.scope.Service;
-import org.apache.polygene.api.service.qualifier.Tagged;
-import org.apache.polygene.api.serialization.Serialization;
 import org.apache.polygene.api.serialization.Serializer;
 import org.apache.polygene.api.value.ValueComposite;
+import org.apache.polygene.spi.serialization.JsonSerializer;
 import org.restlet.Response;
 import org.restlet.data.MediaType;
 import org.restlet.representation.Representation;
@@ -53,8 +52,7 @@ public class ValueCompositeResponseWriter extends AbstractResponseWriter
     private Configuration cfg;
 
     @Service
-    @Tagged( Serialization.Format.JSON )
-    private Serializer serializer;
+    private JsonSerializer serializer;
 
     @Override
     public boolean writeResponse( final Object result, final Response response )
@@ -65,7 +63,7 @@ public class ValueCompositeResponseWriter extends AbstractResponseWriter
             MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes
).getMediaType();
             if( MediaType.APPLICATION_JSON.equals( type ) )
             {
-                StringRepresentation representation = new StringRepresentation( serializer.serialize(
result ),
+                StringRepresentation representation = new StringRepresentation( serializer.serialize(
Serializer.Options.ALL_TYPE_INFO, result ),
                                                                                 MediaType.APPLICATION_JSON
);
                 response.setEntity( representation );
                 return true;

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/b2ff271b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java
----------------------------------------------------------------------
diff --git a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java
b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java
index c438a5b..cc86a26 100644
--- a/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java
+++ b/libraries/rest-server/src/main/java/org/apache/polygene/library/rest/server/restlet/responsewriter/ValueDescriptorResponseWriter.java
@@ -28,7 +28,6 @@ import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import javax.json.Json;
 import javax.json.JsonException;
 import javax.json.JsonObjectBuilder;
 import javax.json.JsonValue;
@@ -36,6 +35,8 @@ import org.apache.polygene.api.injection.scope.Service;
 import org.apache.polygene.api.injection.scope.Structure;
 import org.apache.polygene.api.structure.ModuleDescriptor;
 import org.apache.polygene.api.value.ValueDescriptor;
+import org.apache.polygene.serialization.javaxjson.JavaxJsonFactories;
+import org.apache.polygene.spi.serialization.JsonSerializer;
 import org.restlet.Response;
 import org.restlet.data.MediaType;
 import org.restlet.representation.Representation;
@@ -57,6 +58,12 @@ public class ValueDescriptorResponseWriter extends AbstractResponseWriter
     private ModuleDescriptor module;
 
     @Service
+    private JsonSerializer jsonSerializer;
+
+    @Service
+    private JavaxJsonFactories json;
+
+    @Service
     private Configuration cfg;
 
     @Override
@@ -69,7 +76,7 @@ public class ValueDescriptorResponseWriter extends AbstractResponseWriter
             if( APPLICATION_JSON.equals( type ) )
             {
                 ValueDescriptor vd = (ValueDescriptor) result;
-                JsonObjectBuilder builder = Json.createObjectBuilder();
+                JsonObjectBuilder builder = json.builderFactory().createObjectBuilder();
                 vd.state().properties().forEach(
                     property ->
                     {
@@ -82,7 +89,7 @@ public class ValueDescriptorResponseWriter extends AbstractResponseWriter
                             }
                             else
                             {
-                                builder.add( property.qualifiedName().name(), o.toString()
);
+                                builder.add( property.qualifiedName().name(), jsonSerializer.toJson(
o ) );
                             }
                         }
                         catch( JsonException ex )


Mime
View raw message