Repository: incubator-streams
Updated Branches:
  refs/heads/master 3c390fd98 -> 2c1272444


resolves STREAMS-407


Project: http://git-wip-us.apache.org/repos/asf/incubator-streams/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-streams/commit/1f5f5e7b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-streams/tree/1f5f5e7b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-streams/diff/1f5f5e7b

Branch: refs/heads/master
Commit: 1f5f5e7b8f38c5f39a7a2fbe3e69aaf486365558
Parents: a726b3c
Author: Steve Blackmon @steveblackmon <sblack...@apache.org>
Authored: Tue Oct 11 15:58:19 2016 -0500
Committer: Steve Blackmon @steveblackmon <sblack...@apache.org>
Committed: Tue Oct 11 15:58:19 2016 -0500

----------------------------------------------------------------------
 streams-pojo/pom.xml                            |  1 +
 .../jackson/StreamsDateTimeDeserializer.java    | 13 +++++-
 .../streams/jackson/StreamsJacksonMapper.java   | 42 ++++++++++++++++----
 .../pojo/StreamsJacksonMapperConfiguration.json | 22 ++++++++++
 4 files changed, 69 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/1f5f5e7b/streams-pojo/pom.xml
----------------------------------------------------------------------
diff --git a/streams-pojo/pom.xml b/streams-pojo/pom.xml
index d9fc264..2453a24 100644
--- a/streams-pojo/pom.xml
+++ b/streams-pojo/pom.xml
@@ -191,6 +191,7 @@
                 <configuration>
                     <sourcePaths>
                         <sourcePath>${basedir}/src/main/jsonschema</sourcePath>
+                        
<sourcePath>${basedir}/src/main/jsonschema/org/apache/streams/pojo</sourcePath>
                         
<sourcePath>${basedir}/src/main/jsonschema/verbs</sourcePath>
                         
<sourcePath>${basedir}/src/main/jsonschema/objectTypes</sourcePath>
                     </sourcePaths>

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/1f5f5e7b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeDeserializer.java
----------------------------------------------------------------------
diff --git 
a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeDeserializer.java
 
b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeDeserializer.java
index 639c5ad..43813d2 100644
--- 
a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeDeserializer.java
+++ 
b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeDeserializer.java
@@ -26,6 +26,8 @@ import org.apache.streams.data.util.RFC3339Utils;
 import org.joda.time.DateTime;
 import org.joda.time.format.DateTimeFormat;
 import org.joda.time.format.DateTimeFormatter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.io.IOException;
 import java.io.Serializable;
@@ -43,14 +45,21 @@ public class StreamsDateTimeDeserializer extends 
StdDeserializer<DateTime> imple
 
     List<DateTimeFormatter> formatters = Lists.newArrayList();
 
+    private final static Logger LOGGER = 
LoggerFactory.getLogger(StreamsDateTimeDeserializer.class);
+
     protected StreamsDateTimeDeserializer(Class<DateTime> dateTimeClass) {
         super(dateTimeClass);
     }
 
     protected StreamsDateTimeDeserializer(Class<DateTime> dateTimeClass, 
List<String> formats) {
         super(dateTimeClass);
-        for( String format : formats )
-            formatters.add(DateTimeFormat.forPattern(format));
+        for( String format : formats ) {
+            try {
+                formatters.add(DateTimeFormat.forPattern(format));
+            } catch (Exception e) {
+                LOGGER.warn("Exception parsing format " + format);
+            }
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/1f5f5e7b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonMapper.java
----------------------------------------------------------------------
diff --git 
a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonMapper.java
 
b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonMapper.java
index ada50e8..2492b2f 100644
--- 
a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonMapper.java
+++ 
b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonMapper.java
@@ -27,8 +27,11 @@ import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.SerializationFeature;
 import com.fasterxml.jackson.module.scala.DefaultScalaModule;
 import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.streams.pojo.StreamsJacksonMapperConfiguration;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * StreamsJacksonMapper is the recommended interface to jackson for any 
streams component.
@@ -39,10 +42,22 @@ import java.util.List;
  */
 public class StreamsJacksonMapper extends ObjectMapper {
 
-    private static final StreamsJacksonMapper INSTANCE = new 
StreamsJacksonMapper();
+    private static Map<StreamsJacksonMapperConfiguration, 
StreamsJacksonMapper> INSTANCE_MAP = Maps.newConcurrentMap();
 
-    public static StreamsJacksonMapper getInstance(){
-        return INSTANCE;
+    private StreamsJacksonMapperConfiguration configuration = new 
StreamsJacksonMapperConfiguration();
+
+    public static StreamsJacksonMapper getInstance() {
+        return getInstance(new StreamsJacksonMapperConfiguration());
+    }
+
+    public static StreamsJacksonMapper 
getInstance(StreamsJacksonMapperConfiguration configuration) {
+        if( INSTANCE_MAP.containsKey(configuration) &&
+                INSTANCE_MAP.get(configuration) != null)
+            return INSTANCE_MAP.get(configuration);
+        else {
+            INSTANCE_MAP.put(configuration, new 
StreamsJacksonMapper(configuration));
+            return INSTANCE_MAP.get(configuration);
+        }
     }
 
     public static StreamsJacksonMapper getInstance(String format){
@@ -68,22 +83,35 @@ public class StreamsJacksonMapper extends ObjectMapper {
      */
     protected StreamsJacksonMapper() {
         super();
-        registerModule(new DefaultScalaModule());
-        registerModule(new StreamsJacksonModule());
+        registerModule(new 
StreamsJacksonModule(configuration.getDateFormats()));
+        if( configuration.getEnableScala())
+            registerModule(new DefaultScalaModule());
         configure();
     }
 
+    @Deprecated
     public StreamsJacksonMapper(String format) {
         super();
-        registerModule(new DefaultScalaModule());
         registerModule(new StreamsJacksonModule(Lists.newArrayList(format)));
+        if( configuration.getEnableScala())
+            registerModule(new DefaultScalaModule());
         configure();
     }
 
+    @Deprecated
     public StreamsJacksonMapper(List<String> formats) {
         super();
-        registerModule(new DefaultScalaModule());
         registerModule(new StreamsJacksonModule(formats));
+        if( configuration.getEnableScala())
+            registerModule(new DefaultScalaModule());
+        configure();
+    }
+
+    public StreamsJacksonMapper(StreamsJacksonMapperConfiguration 
configuration) {
+        super();
+        registerModule(new 
StreamsJacksonModule(configuration.getDateFormats()));
+        if( configuration.getEnableScala())
+            registerModule(new DefaultScalaModule());
         configure();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/1f5f5e7b/streams-pojo/src/main/jsonschema/org/apache/streams/pojo/StreamsJacksonMapperConfiguration.json
----------------------------------------------------------------------
diff --git 
a/streams-pojo/src/main/jsonschema/org/apache/streams/pojo/StreamsJacksonMapperConfiguration.json
 
b/streams-pojo/src/main/jsonschema/org/apache/streams/pojo/StreamsJacksonMapperConfiguration.json
new file mode 100644
index 0000000..5bfd082
--- /dev/null
+++ 
b/streams-pojo/src/main/jsonschema/org/apache/streams/pojo/StreamsJacksonMapperConfiguration.json
@@ -0,0 +1,22 @@
+{
+  "$schema": "http://json-schema.org/draft-03/schema";,
+  "$license": [
+    "http://www.apache.org/licenses/LICENSE-2.0";
+  ],
+  "id": "#",
+  "type": "object",
+  "javaType" : "org.apache.streams.pojo.StreamsJacksonMapperConfiguration",
+  "javaInterfaces": ["java.io.Serializable"],
+  "properties": {
+    "dateFormats": {
+      "type": "array",
+      "items": {
+        "type": "string"
+      }
+    },
+    "enableScala": {
+      "type": "boolean",
+      "default": false
+    }
+  }
+}
\ No newline at end of file

Reply via email to