Author: davidb
Date: Wed Sep 21 10:30:09 2016
New Revision: 1761713

URL: http://svn.apache.org/viewvc?rev=1761713&view=rev
Log:
Felix Converter - move with(converter) from Serializer to (De)Serializing

Modified:
    
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
    
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializerImpl.java
    
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializingImpl.java
    
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
    
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializerImpl.java
    
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
    
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Deserializing.java
    
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializer.java
    
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializing.java
    
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java

Modified: 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonDeserializingImpl.java
 Wed Sep 21 10:30:09 2016
@@ -30,7 +30,7 @@ import org.osgi.service.serializer.Deser
 
 public class JsonDeserializingImpl<T> implements Deserializing<T> {
     private final Class<T> clazz;
-    private final Converter converter;
+    private volatile Converter converter;
 
     public JsonDeserializingImpl(Converter c, Class<T> cls) {
         converter = c;
@@ -71,4 +71,10 @@ public class JsonDeserializingImpl<T> im
             return from(s.next());
         }
     }
+
+    @Override
+    public Deserializing<T> with(Converter c) {
+        converter = c;
+        return this;
+    }
 }

Modified: 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializerImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializerImpl.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializerImpl.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializerImpl.java
 Wed Sep 21 10:30:09 2016
@@ -24,23 +24,17 @@ import java.nio.charset.StandardCharsets
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.TypeReference;
-import org.osgi.service.serializer.Serializer;
 import org.osgi.service.serializer.Deserializing;
+import org.osgi.service.serializer.Serializer;
 import org.osgi.service.serializer.Serializing;
 
 public class JsonSerializerImpl implements Serializer {
-    private Map<String, Object> configuration = new ConcurrentHashMap<>();
-    private ThreadLocal<Boolean> threadLocal = new ThreadLocal<>();
-    private Converter converter = new StandardConverter();
-
-    @Override
-    public Serializer with(Converter c) {
-        converter = c;
-        return this;
-    }
+    private final Map<String, Object> configuration = new 
ConcurrentHashMap<>();
+    private final ThreadLocal<Boolean> threadLocal = new ThreadLocal<>();
+    private final Converter converter = new StandardConverter();
 
     @Override
     public <T> Deserializing<T> deserialize(Class<T> cls) {
@@ -98,14 +92,12 @@ public class JsonSerializerImpl implemen
 
         @Override
         public Serializing ignoreNull() {
-            // TODO Auto-generated method stub
-            return null;
+            return this;
         }
 
         @Override
         public Serializing pretty() {
-            // TODO Auto-generated method stub
-            return null;
+            return this;
         }
 
         @Override
@@ -119,6 +111,12 @@ public class JsonSerializerImpl implemen
             // TODO Auto-generated method stub
             return null;
         }
+
+        @Override
+        public Serializing with(Converter converter) {
+            delegate.with(converter);
+            return this;
+        }
     }
 
     @Override

Modified: 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializingImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializingImpl.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializingImpl.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/json/JsonSerializingImpl.java
 Wed Sep 21 10:30:09 2016
@@ -34,7 +34,7 @@ import org.osgi.service.converter.Conver
 import org.osgi.service.serializer.Serializing;
 
 public class JsonSerializingImpl implements Serializing {
-    private final Converter converter;
+    private volatile Converter converter;
     private final Map<String, Object> configuration;
     private final Object object;
     private final boolean ignoreNull;
@@ -147,14 +147,17 @@ public class JsonSerializingImpl impleme
 
     @Override
     public Serializing ignoreNull() {
-        // TODO Auto-generated method stub
-        return null;
+        return this;
     }
 
     @Override
     public Serializing pretty() {
-        // TODO Auto-generated method stub
-        return null;
+        return this;
     }
 
+    @Override
+    public Serializing with(Converter c) {
+        converter = c;
+        return this;
+    }
 }

Modified: 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlDeserializingImpl.java
 Wed Sep 21 10:30:09 2016
@@ -29,7 +29,7 @@ import org.osgi.service.serializer.Deser
 import org.yaml.snakeyaml.Yaml;
 
 public class YamlDeserializingImpl<T> implements Deserializing<T> {
-    private final Converter converter;
+    private volatile Converter converter;
     private final Class<T> clazz;
 
     public YamlDeserializingImpl(Converter c, Class<T> cls) {
@@ -72,4 +72,10 @@ public class YamlDeserializingImpl<T> im
 
         return converter.convert(res).to(clazz);
     }
+
+    @Override
+    public Deserializing<T> with(Converter c) {
+        converter = c;
+        return this;
+    }
 }

Modified: 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializerImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializerImpl.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializerImpl.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializerImpl.java
 Wed Sep 21 10:30:09 2016
@@ -20,22 +20,16 @@ import java.lang.reflect.Type;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.TypeReference;
-import org.osgi.service.serializer.Serializer;
 import org.osgi.service.serializer.Deserializing;
+import org.osgi.service.serializer.Serializer;
 import org.osgi.service.serializer.Serializing;
 
 public class YamlSerializerImpl implements Serializer {
-    private Map<String, Object> configuration = new ConcurrentHashMap<>();
-    private Converter converter = new StandardConverter();
-
-    @Override
-    public Serializer with(Converter c) {
-        converter = c;
-        return this;
-    }
+    private final Map<String, Object> configuration = new 
ConcurrentHashMap<>();
+    private final Converter converter = new StandardConverter();
 
     @Override
     public <T> Deserializing<T> deserialize(Class<T> cls) {

Modified: 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/apache/felix/serializer/impl/yaml/YamlSerializingImpl.java
 Wed Sep 21 10:30:09 2016
@@ -33,7 +33,7 @@ import org.osgi.service.converter.Conver
 import org.osgi.service.serializer.Serializing;
 
 public class YamlSerializingImpl implements Serializing {
-    private final Converter converter;
+    private volatile Converter converter;
     private final Map<String, Object> configuration;
     private final Object object;
     private final int indentation = 2;
@@ -143,13 +143,17 @@ public class YamlSerializingImpl impleme
 
     @Override
     public Serializing pretty() {
-        // TODO Auto-generated method stub
-        return null;
+        return this;
     }
 
     @Override
     public Serializing ignoreNull() {
-        // TODO Auto-generated method stub
-        return null;
+        return this;
+    }
+
+    @Override
+    public Serializing with(Converter c) {
+        converter = c;
+        return this;
     }
 }

Modified: 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Deserializing.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Deserializing.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Deserializing.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Deserializing.java
 Wed Sep 21 10:30:09 2016
@@ -19,6 +19,7 @@ import java.io.InputStream;
 import java.nio.charset.Charset;
 
 import org.osgi.annotation.versioning.ProviderType;
+import org.osgi.service.converter.Converter;
 
 /**
  * Interface to specify the source of the decoding operation
@@ -62,4 +63,13 @@ public interface Deserializing<T> {
         * @return the decoded object.
         */
        T from(CharSequence in);
+
+    /**
+     * Specify the converter to be used by the code, if an alternative, 
adapted,
+     * converter is to be used.
+     *
+     * @param converter The converter to use.
+     * @return A codec that uses the converter as specified.
+     */
+       Deserializing<T> with(Converter converter);
 }

Modified: 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializer.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializer.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializer.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializer.java
 Wed Sep 21 10:30:09 2016
@@ -18,7 +18,6 @@ package org.osgi.service.serializer;
 import java.lang.reflect.Type;
 
 import org.osgi.annotation.versioning.ProviderType;
-import org.osgi.service.converter.Converter;
 import org.osgi.service.converter.TypeReference;
 
 /**
@@ -70,13 +69,4 @@ public interface Serializer {
         *         operation.
         */
        Serializing serialize(Object obj);
-
-       /**
-        * Specify the converter to be used by the code, if an alternative, 
adapted,
-        * converter is to be used.
-        *
-        * @param converter The converter to use.
-        * @return A codec that uses the converter as specified.
-        */
-       Serializer with(Converter converter);
 }

Modified: 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializing.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializing.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializing.java
 (original)
+++ 
felix/trunk/converter/serializer/src/main/java/org/osgi/service/serializer/Serializing.java
 Wed Sep 21 10:30:09 2016
@@ -20,6 +20,7 @@ import java.io.OutputStream;
 import java.nio.charset.Charset;
 
 import org.osgi.annotation.versioning.ProviderType;
+import org.osgi.service.converter.Converter;
 
 /**
  * Interface to specify the target of the encoding operation.
@@ -33,7 +34,7 @@ public interface Serializing {
         * Specify that keys with a {@code null} value must not appear in the
         * result. If not specified {@code null} values will be included in the
         * result.
-        * 
+        *
         * @return This Encoding object to allow further invocations on it.
         */
        Serializing ignoreNull();
@@ -47,6 +48,16 @@ public interface Serializing {
         */
        Serializing pretty();
 
+    /**
+     * Specify the converter to be used by the code, if an alternative, 
adapted,
+     * converter is to be used.
+     *
+     * @param converter The converter to use.
+     * @return A codec that uses the converter as specified.
+     */
+    Serializing with(Converter converter);
+
+
        /**
         * Use an output stream as the target of the encoding operation. UTF-8 
will
         * be used if applicable, the character set may not apply to binary

Modified: 
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java?rev=1761713&r1=1761712&r2=1761713&view=diff
==============================================================================
--- 
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java
 (original)
+++ 
felix/trunk/converter/serializer/src/test/java/org/apache/felix/serializer/impl/json/JsonSerializerTest.java
 Wed Sep 21 10:30:09 2016
@@ -19,7 +19,6 @@ package org.apache.felix.serializer.impl
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.felix.serializer.impl.json.JsonSerializerImpl;
 import org.apache.felix.serializer.impl.json.MyDTO.Count;
 import org.apache.felix.serializer.impl.json.MyEmbeddedDTO.Alpha;
 import org.apache.sling.commons.json.JSONException;
@@ -28,8 +27,8 @@ import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.osgi.service.converter.Adapter;
-import org.osgi.service.converter.StandardConverter;
 import org.osgi.service.converter.Converter;
+import org.osgi.service.converter.StandardConverter;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -87,7 +86,7 @@ public class JsonSerializerTest {
         ca.rule(Foo.class, String.class, Foo::tsFun, v -> Foo.fsFun(v));
 
         JsonSerializerImpl jsonCodec = new JsonSerializerImpl();
-        String json = jsonCodec.with(ca).serialize(m).toString();
+        String json = jsonCodec.serialize(m).with(ca).toString();
 
         JSONObject jo = new JSONObject(json);
         assertEquals(1, jo.length());


Reply via email to