You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by sb...@apache.org on 2016/11/25 20:24:51 UTC
[10/42] incubator-streams git commit: STREAMS-440: custom
checkstyle.xml, address compliance
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java b/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
index bcb14b7..b15722f 100644
--- a/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
+++ b/streams-pojo/src/main/java/org/apache/streams/data/DocumentClassifier.java
@@ -27,13 +27,13 @@ import java.util.List;
*/
public interface DocumentClassifier extends Serializable {
- /**
- * Assess the structure of the document, and identify whether the provided document is
- * a structural match for one or more typed forms.
- *
- * @param document the document
- * @return a serializable pojo class this document matches
- */
- List<Class> detectClasses(Object document);
+ /**
+ * Assess the structure of the document, and identify whether the provided document is
+ * a structural match for one or more typed forms.
+ *
+ * @param document the document
+ * @return a serializable pojo class this document matches
+ */
+ List<Class> detectClasses(Object document);
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/data/util/ActivityUtil.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/data/util/ActivityUtil.java b/streams-pojo/src/main/java/org/apache/streams/data/util/ActivityUtil.java
index dc10df1..c7e8337 100644
--- a/streams-pojo/src/main/java/org/apache/streams/data/util/ActivityUtil.java
+++ b/streams-pojo/src/main/java/org/apache/streams/data/util/ActivityUtil.java
@@ -18,123 +18,140 @@
package org.apache.streams.data.util;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.streams.jackson.StreamsJacksonMapper;
import org.apache.streams.pojo.json.Activity;
import org.apache.streams.pojo.json.ActivityObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.util.HashMap;
import java.util.Map;
/**
* Utility class for managing activities
*
+ * <p/>
* Deprecated: Use {@link org.apache.streams.pojo.extensions.ExtensionUtil}
*/
@Deprecated
public class ActivityUtil {
- private ActivityUtil() {}
-
- /**
- * Property on the activity object to use for extensions
- */
- public static final String EXTENSION_PROPERTY = "extensions";
- /**
- * The number of +1, Like, favorites, etc that the post has received
- */
- public static final String LIKES_EXTENSION = "likes";
- /**
- * The number of retweets, shares, etc that the post has received
- */
- public static final String REBROADCAST_EXTENSION = "rebroadcasts";
- /**
- * The language of the post
- */
- public static final String LANGUAGE_EXTENSION = "language";
- /**
- * Location that the post was made or the actor's residence
- */
- public static final String LOCATION_EXTENSION = "location";
- /**
- * Country that the post was made
- */
- public static final String LOCATION_EXTENSION_COUNTRY = "country";
- /**
- * Specific JSON-geo coordinates (long,lat)
- */
- public static final String LOCATION_EXTENSION_COORDINATES = "coordinates";
-
- private static final ObjectMapper mapper = StreamsJacksonMapper.getInstance();
-
- /**
- * Creates a standard extension property
- * @param activity activity to create the property in
- * @return the Map representing the extensions property
- */
- @SuppressWarnings("unchecked")
- @Deprecated
- public static Map<String, Object> ensureExtensions(Activity activity) {
- Map<String, Object> extensions = (Map)activity.getAdditionalProperties().get(EXTENSION_PROPERTY);
- if(extensions == null) {
- extensions = new HashMap<>();
- activity.setAdditionalProperty(EXTENSION_PROPERTY, extensions);
- }
- return extensions;
- }
+ private ActivityUtil() {}
- /**
- * Gets a formatted ID
- * @param providerName name of the provider
- * @param personId ID of the person within the system
- * @return id:<providerName>:people:<personId>
- */
- public static String getPersonId(String providerName, String personId) {
- return String.format("id:%s:people:%s", providerName, personId);
- }
+ /**
+ * Property on the activity object to use for extensions.
+ */
+ public static final String EXTENSION_PROPERTY = "extensions";
- /**
- * Gets a formatted provider ID
- * @param providerName name of the provider
- * @return id:providers:<providerName>
- */
- public static String getProviderId(String providerName) {
- return String.format("id:providers:%s", providerName);
- }
+ /**
+ * The number of +1, Like, favorites, etc that the post has received.
+ */
+ public static final String LIKES_EXTENSION = "likes";
- /**
- * Gets a formatted object ID
- * @param provider name of the provider
- * @param objectType type of the object
- * @param objectId the ID of the object
- * @return id:<provider>:<objectType>s:<objectId>
- */
- public static String getObjectId(String provider, String objectType, String objectId) {
- return String.format("id:%s:%ss:%s", provider, objectType, objectId);
- }
+ /**
+ * The number of retweets, shares, etc that the post has received.
+ */
+ public static final String REBROADCAST_EXTENSION = "rebroadcasts";
- /**
- * Gets a formatted activity ID
- * @param providerName name of the provider
- * @param activityId ID of the provider
- * @return id:<providerName>:activities:<activityId>
- */
- public static String getActivityId(String providerName, String activityId) {
- return String.format("id:%s:activities:%s", providerName, activityId);
- }
+ /**
+ * The language of the post.
+ */
+ public static final String LANGUAGE_EXTENSION = "language";
- public static boolean isValid(Activity activity) {
- return activity != null
- && activity.getId() != null
- && activity.getVerb() != null
- && activity.getProvider() != null
- && activity.getProvider().getId() != null;
- }
+ /**
+ * Location that the post was made or the actor's residence.
+ */
+ public static final String LOCATION_EXTENSION = "location";
- public static boolean isValid(ActivityObject activityObject) {
- return activityObject != null
- && activityObject.getId() != null
- && activityObject.getObjectType() != null;
+ /**
+ * Country that the post was made.
+ */
+ public static final String LOCATION_EXTENSION_COUNTRY = "country";
+
+ /**
+ * Specific JSON-geo coordinates (long,lat).
+ */
+ public static final String LOCATION_EXTENSION_COORDINATES = "coordinates";
+
+ private static final ObjectMapper mapper = StreamsJacksonMapper.getInstance();
+
+ /**
+ * Creates a standard extension property.
+ * @param activity activity to create the property in
+ * @return the Map representing the extensions property
+ */
+ @SuppressWarnings("unchecked")
+ @Deprecated
+ public static Map<String, Object> ensureExtensions(Activity activity) {
+ Map<String, Object> extensions = (Map)activity.getAdditionalProperties().get(EXTENSION_PROPERTY);
+ if (extensions == null) {
+ extensions = new HashMap<>();
+ activity.setAdditionalProperty(EXTENSION_PROPERTY, extensions);
}
+ return extensions;
+ }
+
+ /**
+ * Gets a formatted ID.
+ * @param providerName name of the provider
+ * @param personId ID of the person within the system
+ * @return id:{providerName}:people:{personId}
+ */
+ public static String getPersonId(String providerName, String personId) {
+ return String.format("id:%s:people:%s", providerName, personId);
+ }
+
+ /**
+ * Gets a formatted provider ID.
+ * @param providerName name of the provider
+ * @return id:providers:{providerName}
+ */
+ public static String getProviderId(String providerName) {
+ return String.format("id:providers:%s", providerName);
+ }
+
+ /**
+ * Gets a formatted object ID.
+ * @param provider name of the provider
+ * @param objectType type of the object
+ * @param objectId the ID of the object
+ * @return id:{provider}:{objectType}s:{objectId}
+ */
+ public static String getObjectId(String provider, String objectType, String objectId) {
+ return String.format("id:%s:%ss:%s", provider, objectType, objectId);
+ }
+
+ /**
+ * Gets a formatted activity ID.
+ * @param providerName name of the provider
+ * @param activityId ID of the provider
+ * @return id:{providerName}:activities:{activityId}
+ */
+ public static String getActivityId(String providerName, String activityId) {
+ return String.format("id:%s:activities:%s", providerName, activityId);
+ }
+
+ /**
+ * Check validity of Activity.
+ * @param activity Activity
+ * @return isValid
+ */
+ public static boolean isValid(Activity activity) {
+ return activity != null
+ && activity.getId() != null
+ && activity.getVerb() != null
+ && activity.getProvider() != null
+ && activity.getProvider().getId() != null;
+ }
+
+ /**
+ * Check validity of ActivityObject.
+ * @param activityObject ActivityObject
+ * @return isValid
+ */
+ public static boolean isValid(ActivityObject activityObject) {
+ return activityObject != null
+ && activityObject.getId() != null
+ && activityObject.getObjectType() != null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/data/util/JsonUtil.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/data/util/JsonUtil.java b/streams-pojo/src/main/java/org/apache/streams/data/util/JsonUtil.java
deleted file mode 100644
index 6ab2800..0000000
--- a/streams-pojo/src/main/java/org/apache/streams/data/util/JsonUtil.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * 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
- *
- * 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.streams.data.util;
-
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ArrayNode;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
-import com.google.common.collect.Lists;
-import org.apache.streams.jackson.StreamsJacksonMapper;
-
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * JSON utilities
- */
-public class JsonUtil {
-
- private JsonUtil() {}
-
- private static ObjectMapper mapper = StreamsJacksonMapper.getInstance();
- private static JsonFactory factory = mapper.getFactory();
-
- public static JsonNode jsonToJsonNode(String json) {
- JsonNode node;
- try {
- JsonParser jp = factory.createJsonParser(json);
- node = mapper.readTree(jp);
- } catch (IOException e) {
- throw new RuntimeException("IO exception while reading JSON", e);
- }
- return node;
- }
-
- public static String jsonNodeToJson(JsonNode node) {
- try {
- return mapper.writeValueAsString(node);
- } catch (JsonProcessingException e) {
- throw new RuntimeException("IO exception while writing JSON", e);
- }
- }
-
- public static <T> T jsonToObject(String json, Class<T> clazz) {
- try {
- return mapper.readValue(json, clazz);
- } catch (IOException e) {
- throw new RuntimeException("Could not map to object");
- }
- }
-
- public static <T> T jsonNodeToObject(JsonNode node, Class<T> clazz) {
- return mapper.convertValue(node, clazz);
- }
-
- public static <T> JsonNode objectToJsonNode(T obj) {
- return mapper.valueToTree(obj);
- }
-
- public static <T> List<T> jsoNodeToList(JsonNode node, Class<T> clazz) {
- return mapper.convertValue(node, new TypeReference<List<T>>() {});
- }
-
- public static <T> String objectToJson(T object) {
- try {
- return mapper.writeValueAsString(object);
- } catch (IOException e) {
- throw new RuntimeException("Could not map to object");
- }
- }
-
- public static <T> T getObjFromFile(String filePath, Class<T> clazz) {
- return jsonNodeToObject(getFromFile(filePath), clazz);
- }
-
- public static JsonNode getFromFile(String filePath) {
- JsonFactory factory = mapper.getFactory(); // since 2.1 use mapper.getFactory() instead
-
- JsonNode node = null;
- try {
- InputStream stream = getStreamForLocation(filePath);
- JsonParser jp = factory.createParser(stream);
- node = mapper.readTree(jp);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return node;
- }
-
- private static InputStream getStreamForLocation(String filePath) throws FileNotFoundException {
- InputStream stream = null;
- if(filePath.startsWith("file:///")) {
- stream = new FileInputStream(filePath.replace("file:///", ""));
- } else if(filePath.startsWith("file:") || filePath.startsWith("/")) {
- stream = new FileInputStream(filePath.replace("file:", ""));
- } else {
- //Assume classpath
- stream = JsonUtil.class.getClassLoader().getResourceAsStream(filePath.replace("classpath:", ""));
- }
-
- return stream;
- }
-
- /**
- * Creates an empty array if missing
- * @param node object to create the array within
- * @param field location to create the array
- * @return the Map representing the extensions property
- */
- public static ArrayNode ensureArray(ObjectNode node, String field) {
- String[] path = Lists.newArrayList(Splitter.on('.').split(field)).toArray(new String[0]);
- ObjectNode current = node;
- ArrayNode result = null;
- for( int i = 0; i < path.length; i++) {
- current = ensureObject((ObjectNode) node.get(path[i]), path[i]);
- }
- if (current.get(field) == null)
- current.put(field, mapper.createArrayNode());
- result = (ArrayNode) node.get(field);
- return result;
- }
-
- /**
- * Creates an empty array if missing
- * @param node objectnode to create the object within
- * @param field location to create the object
- * @return the Map representing the extensions property
- */
- public static ObjectNode ensureObject(ObjectNode node, String field) {
- String[] path = Lists.newArrayList(Splitter.on('.').split(field)).toArray(new String[0]);
- ObjectNode current = node;
- ObjectNode result = null;
- for( int i = 0; i < path.length; i++) {
- if (node.get(field) == null)
- node.put(field, mapper.createObjectNode());
- current = (ObjectNode) node.get(field);
- }
- result = ensureObject((ObjectNode) node.get(path[path.length]), Joiner.on('.').join(Arrays.copyOfRange(path, 1, path.length)));
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/data/util/RFC3339Utils.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/data/util/RFC3339Utils.java b/streams-pojo/src/main/java/org/apache/streams/data/util/RFC3339Utils.java
index bd32668..18ae064 100644
--- a/streams-pojo/src/main/java/org/apache/streams/data/util/RFC3339Utils.java
+++ b/streams-pojo/src/main/java/org/apache/streams/data/util/RFC3339Utils.java
@@ -15,6 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.streams.data.util;
import org.joda.time.DateTime;
@@ -33,172 +34,176 @@ import java.util.regex.Pattern;
*/
public class RFC3339Utils {
- private static final RFC3339Utils INSTANCE = new RFC3339Utils();
-
- public static RFC3339Utils getInstance(){
- return INSTANCE;
- }
-
- private static final String BASE = "^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}";
- private static final String TZ = "[+-][0-9]{2}:?[0-9]{2}$";
- private static final String SUB_SECOND = "\\.([0-9]*)";
- private static final String UTC = "Z$";
-
-
- private static final Pattern MILLIS = Pattern.compile("^[0-9]*$");
- private static final Pattern UTC_STANDARD = Pattern.compile(BASE + UTC);
- private static final Pattern UTC_SUB_SECOND = Pattern.compile(BASE + SUB_SECOND + UTC);
- private static final Pattern LOCAL_STANDARD = Pattern.compile(BASE + TZ);
- private static final Pattern LOCAL_SUB_SECOND = Pattern.compile(BASE + SUB_SECOND + TZ);
-
- private static final String BASE_FMT = "yyyy-MM-dd'T'HH:mm:ss";
- public static final DateTimeFormatter UTC_STANDARD_FMT = DateTimeFormat.forPattern(BASE_FMT + "'Z'").withZoneUTC();
- public static final DateTimeFormatter UTC_SUB_SECOND_FMT = DateTimeFormat.forPattern(BASE_FMT + ".SSS'Z'").withZoneUTC();
- public static final DateTimeFormatter LOCAL_STANDARD_FMT = DateTimeFormat.forPattern(BASE_FMT + "Z").withZoneUTC();
- public static final DateTimeFormatter LOCAL_SUB_SECOND_FMT = DateTimeFormat.forPattern(BASE_FMT + ".SSSZ").withZoneUTC();
-
- /**
- * Contains various formats. All formats should be of international standards when comes to the ordering of the
- * days and month.
- */
- private static final DateTimeFormatter DEFAULT_FORMATTER;
- /**
- * Contains alternative formats that will succeed after failures from the DEFAULT_FORMATTER.
- * i.e. 4/24/2014 will throw an exception on the default formatter because it will assume international date standards
- * However, the date will parse in the ALT_FORMATTER because it contains the US format of MM/dd/yyyy.
- */
- private static final DateTimeFormatter ALT_FORMATTER;
-
- static {
- DateTimeParser[] parsers = new DateTimeParser[]{
- DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss Z yyyy").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z").getParser(),
- DateTimeFormat.forPattern("dd MMMM yyyy HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyyMMdd").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd-MM-yyyy").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyy/MM/dd").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd MMM yyyy").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd MMMM yyyy").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyyMMddHHmm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyyMMdd HHmm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd-MM-yyyy HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyy/MM/dd HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd MMM yyyy HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd MMMM yyyy HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyyMMddHHmmss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyyMMdd HHmmss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd-MM-yyyy HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd MMM yyyy HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("HH:mm:ss yyyy/MM/dd").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("HH:mm:ss MM/dd/yyyy").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("HH:mm:ss yyyy-MM-dd").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("HH:mm:ss MM-dd-yyyy").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd/MM/yyyy HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("dd/MM/yyyy").withZoneUTC().getParser(),
- UTC_STANDARD_FMT.getParser(),
- UTC_SUB_SECOND_FMT.getParser(),
- LOCAL_STANDARD_FMT.getParser(),
- LOCAL_SUB_SECOND_FMT.getParser()
- };
- DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
- builder.append(null, parsers);
- DEFAULT_FORMATTER = builder.toFormatter().withZoneUTC();
-
- DateTimeParser[] altParsers = new DateTimeParser[] {
- DateTimeFormat.forPattern("MM-dd-yyyy HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("MM/dd/yyyy HH:mm").withZoneUTC().getParser(),
- DateTimeFormat.forPattern("MM/dd/yyyy").withZoneUTC().getParser(),
- };
- builder = new DateTimeFormatterBuilder();
- builder.append(null, altParsers);
- ALT_FORMATTER = builder.toFormatter().withZoneUTC();
+ private static final RFC3339Utils INSTANCE = new RFC3339Utils();
+
+ public static RFC3339Utils getInstance() {
+ return INSTANCE;
+ }
+
+ private static final String BASE = "^[0-9]{4}\\-[0-9]{2}\\-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}";
+ private static final String TZ = "[+-][0-9]{2}:?[0-9]{2}$";
+ private static final String SUB_SECOND = "\\.([0-9]*)";
+ private static final String UTC = "Z$";
+
+
+ private static final Pattern MILLIS = Pattern.compile("^[0-9]*$");
+ private static final Pattern UTC_STANDARD = Pattern.compile(BASE + UTC);
+ private static final Pattern UTC_SUB_SECOND = Pattern.compile(BASE + SUB_SECOND + UTC);
+ private static final Pattern LOCAL_STANDARD = Pattern.compile(BASE + TZ);
+ private static final Pattern LOCAL_SUB_SECOND = Pattern.compile(BASE + SUB_SECOND + TZ);
+
+ private static final String BASE_FMT = "yyyy-MM-dd'T'HH:mm:ss";
+ public static final DateTimeFormatter UTC_STANDARD_FMT = DateTimeFormat.forPattern(BASE_FMT + "'Z'").withZoneUTC();
+ public static final DateTimeFormatter UTC_SUB_SECOND_FMT = DateTimeFormat.forPattern(BASE_FMT + ".SSS'Z'").withZoneUTC();
+ public static final DateTimeFormatter LOCAL_STANDARD_FMT = DateTimeFormat.forPattern(BASE_FMT + "Z").withZoneUTC();
+ public static final DateTimeFormatter LOCAL_SUB_SECOND_FMT = DateTimeFormat.forPattern(BASE_FMT + ".SSSZ").withZoneUTC();
+
+ /**
+ * Contains various formats. All formats should be of international standards when comes to the ordering of the
+ * days and month.
+ */
+ private static final DateTimeFormatter DEFAULT_FORMATTER;
+ /**
+ * Contains alternative formats that will succeed after failures from the DEFAULT_FORMATTER.
+ * i.e. 4/24/2014 will throw an exception on the default formatter because it will assume international date standards
+ * However, the date will parse in the ALT_FORMATTER because it contains the US format of MM/dd/yyyy.
+ */
+ private static final DateTimeFormatter ALT_FORMATTER;
+
+ static {
+ DateTimeParser[] parsers = new DateTimeParser[]{
+ DateTimeFormat.forPattern("EEE MMM dd HH:mm:ss Z yyyy").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z").getParser(),
+ DateTimeFormat.forPattern("dd MMMM yyyy HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyyMMdd").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd-MM-yyyy").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyy-MM-dd").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyy/MM/dd").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd MMM yyyy").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd MMMM yyyy").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyyMMddHHmm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyyMMdd HHmm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd-MM-yyyy HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyy/MM/dd HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd MMM yyyy HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd MMMM yyyy HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyyMMddHHmmss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyyMMdd HHmmss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd-MM-yyyy HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("yyyy/MM/dd HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd MMM yyyy HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("HH:mm:ss yyyy/MM/dd").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("HH:mm:ss MM/dd/yyyy").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("HH:mm:ss yyyy-MM-dd").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("HH:mm:ss MM-dd-yyyy").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd/MM/yyyy HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("dd/MM/yyyy").withZoneUTC().getParser(),
+ UTC_STANDARD_FMT.getParser(),
+ UTC_SUB_SECOND_FMT.getParser(),
+ LOCAL_STANDARD_FMT.getParser(),
+ LOCAL_SUB_SECOND_FMT.getParser()
+ };
+ DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder();
+ builder.append(null, parsers);
+ DEFAULT_FORMATTER = builder.toFormatter().withZoneUTC();
+
+ DateTimeParser[] altParsers = new DateTimeParser[] {
+ DateTimeFormat.forPattern("MM-dd-yyyy HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("MM/dd/yyyy HH:mm:ss").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("MM/dd/yyyy HH:mm").withZoneUTC().getParser(),
+ DateTimeFormat.forPattern("MM/dd/yyyy").withZoneUTC().getParser(),
+ };
+ builder = new DateTimeFormatterBuilder();
+ builder.append(null, altParsers);
+ ALT_FORMATTER = builder.toFormatter().withZoneUTC();
+ }
+
+ private RFC3339Utils() {}
+
+ /**
+ * parse String to DateTime
+ * @param toParse DateTime as UTC String
+ * @return DateTime
+ */
+ public static DateTime parseUTC(String toParse) {
+ if (MILLIS.matcher(toParse).matches()) {
+ return new DateTime(Long.valueOf(toParse), DateTimeZone.UTC);
}
-
-
- private RFC3339Utils() {}
-
- public static DateTime parseUTC(String toParse) {
- if(MILLIS.matcher(toParse).matches()) {
- return new DateTime(Long.valueOf(toParse), DateTimeZone.UTC);
- }
- if(UTC_STANDARD.matcher(toParse).matches()) {
- return parseUTC(UTC_STANDARD_FMT, toParse);
- }
- Matcher utc = UTC_SUB_SECOND.matcher(toParse);
- if(utc.matches()) {
- return parseUTC(getSubSecondFormat(utc.group(1), "'Z'"), toParse);
- }
- if(LOCAL_STANDARD.matcher(toParse).matches()) {
- return parseUTC(LOCAL_STANDARD_FMT, toParse);
- }
- Matcher local = LOCAL_SUB_SECOND.matcher(toParse);
- if(local.matches()) {
- return parseUTC(getSubSecondFormat(local.group(1), "Z"), toParse);
- }
- throw new IllegalArgumentException(String.format("Failed to parse date %s. Ensure format is RFC3339 Compliant", toParse));
+ if (UTC_STANDARD.matcher(toParse).matches()) {
+ return parseUTC(UTC_STANDARD_FMT, toParse);
}
-
- public static String format(DateTime toFormat) {
- return UTC_SUB_SECOND_FMT.print(toFormat.getMillis());
+ Matcher utc = UTC_SUB_SECOND.matcher(toParse);
+ if (utc.matches()) {
+ return parseUTC(getSubSecondFormat(utc.group(1), "'Z'"), toParse);
}
-
- public static String format(DateTime toFormat, TimeZone tz) {
- return LOCAL_SUB_SECOND_FMT.withZone(DateTimeZone.forTimeZone(tz)).print(toFormat.getMillis());
+ if (LOCAL_STANDARD.matcher(toParse).matches()) {
+ return parseUTC(LOCAL_STANDARD_FMT, toParse);
}
-
- /**
- * Parses arbitrarily formatted Strings representing dates or dates and times to a {@link org.joda.time.DateTime}
- * objects. It first attempts parse with international standards, assuming the dates are either dd MM yyyy or
- * yyyy MM dd. If that fails it will try American formats where the month precedes the days of the month.
- * @param dateString abitrarily formatted date or date and time string
- * @return {@link org.joda.time.DateTime} representation of the dateString
- */
- public static DateTime parseToUTC(String dateString) {
- if(MILLIS.matcher(dateString).find()) {
- return new DateTime(Long.parseLong(dateString));
- }
- try {
- return DEFAULT_FORMATTER.parseDateTime(dateString);
- } catch (Exception e) {
- return ALT_FORMATTER.parseDateTime(dateString);
- }
+ Matcher local = LOCAL_SUB_SECOND.matcher(toParse);
+ if (local.matches()) {
+ return parseUTC(getSubSecondFormat(local.group(1), "Z"), toParse);
}
-
- /**
- * Formats an arbitrarily formatted into RFC3339 Specifications.
- * @param dateString date string to be formatted
- * @return RFC3339 compliant date string
- */
- public static String format(String dateString) {
- return format(parseToUTC(dateString));
+ throw new IllegalArgumentException(String.format("Failed to parse date %s. Ensure format is RFC3339 Compliant", toParse));
+ }
+
+ private static DateTime parseUTC(DateTimeFormatter formatter, String toParse) {
+ return formatter.parseDateTime(toParse);
+ }
+
+ /**
+ * Parses arbitrarily formatted Strings representing dates or dates and times to a {@link org.joda.time.DateTime}
+ * objects. It first attempts parse with international standards, assuming the dates are either dd MM yyyy or
+ * yyyy MM dd. If that fails it will try American formats where the month precedes the days of the month.
+ * @param dateString abitrarily formatted date or date and time string
+ * @return {@link org.joda.time.DateTime} representation of the dateString
+ */
+ public static DateTime parseToUTC(String dateString) {
+ if (MILLIS.matcher(dateString).find()) {
+ return new DateTime(Long.parseLong(dateString));
}
-
- private static DateTime parseUTC(DateTimeFormatter formatter, String toParse) {
- return formatter.parseDateTime(toParse);
+ try {
+ return DEFAULT_FORMATTER.parseDateTime(dateString);
+ } catch (Exception ex) {
+ return ALT_FORMATTER.parseDateTime(dateString);
}
-
- private static DateTimeFormatter getSubSecondFormat(String sub, String suffix) {
- DateTimeFormatter result;
- //Since RFC3339 allows for any number of sub-second notations, we need to flexibly support more or less than 3
- //digits; however, if it is exactly 3, just use the standards.
- if(sub.length() == 3) {
- result = suffix.equals("Z") ? LOCAL_SUB_SECOND_FMT : UTC_SUB_SECOND_FMT;
- } else {
- StringBuilder pattern = new StringBuilder();
- pattern.append(BASE_FMT);
- pattern.append(".");
- for (int i = 0; i < sub.length(); i++) {
- pattern.append("S");
- }
- pattern.append(suffix);
- result = DateTimeFormat.forPattern(pattern.toString()).withZoneUTC();
- }
- return result;
+ }
+
+ /**
+ * Formats an arbitrarily formatted into RFC3339 Specifications.
+ * @param dateString date string to be formatted
+ * @return RFC3339 compliant date string
+ */
+ public static String format(String dateString) {
+ return format(parseToUTC(dateString));
+ }
+
+ public static String format(DateTime toFormat) {
+ return UTC_SUB_SECOND_FMT.print(toFormat.getMillis());
+ }
+
+ public static String format(DateTime toFormat, TimeZone tz) {
+ return LOCAL_SUB_SECOND_FMT.withZone(DateTimeZone.forTimeZone(tz)).print(toFormat.getMillis());
+ }
+
+ private static DateTimeFormatter getSubSecondFormat(String sub, String suffix) {
+ DateTimeFormatter result;
+ //Since RFC3339 allows for any number of sub-second notations, we need to flexibly support more or less than 3
+ //digits; however, if it is exactly 3, just use the standards.
+ if (sub.length() == 3) {
+ result = suffix.equals("Z") ? LOCAL_SUB_SECOND_FMT : UTC_SUB_SECOND_FMT;
+ } else {
+ StringBuilder pattern = new StringBuilder();
+ pattern.append(BASE_FMT);
+ pattern.append(".");
+ for (int i = 0; i < sub.length(); i++) {
+ pattern.append("S");
+ }
+ pattern.append(suffix);
+ result = DateTimeFormat.forPattern(pattern.toString()).withZoneUTC();
}
+ return result;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityConversionException.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityConversionException.java b/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityConversionException.java
index a03ec87..96c4bb1 100644
--- a/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityConversionException.java
+++ b/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityConversionException.java
@@ -19,24 +19,24 @@
package org.apache.streams.exceptions;
/**
- * ActivityConversionException is a typed exception appropriate when a valid Activity
- * cannot be created from a given document.
+ * ActivityConversionException is a typed exception appropriate when a valid Activity
+ * cannot be created from a given document.
*/
public class ActivityConversionException extends Exception {
- public ActivityConversionException() {
- }
+ public ActivityConversionException() {
+ }
- public ActivityConversionException(String message) {
- super(message);
- }
+ public ActivityConversionException(String message) {
+ super(message);
+ }
- public ActivityConversionException(Throwable cause) {
- super(cause);
- }
+ public ActivityConversionException(Throwable cause) {
+ super(cause);
+ }
- public ActivityConversionException(String message, Throwable cause) {
- super(message, cause);
- }
+ public ActivityConversionException(String message, Throwable cause) {
+ super(message, cause);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityDeserializerException.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityDeserializerException.java b/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityDeserializerException.java
deleted file mode 100644
index 70901d9..0000000
--- a/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivityDeserializerException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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
- *
- * 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.streams.exceptions;
-
-/**
- * Created by sblackmon on 3/25/14.
- */
-public class ActivityDeserializerException extends Exception {
-
- public ActivityDeserializerException() {
- // TODO Auto-generated constructor stub
- }
-
- public ActivityDeserializerException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
-
- public ActivityDeserializerException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
-
- public ActivityDeserializerException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivitySerializerException.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivitySerializerException.java b/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivitySerializerException.java
index e58e2da..85a3b8f 100644
--- a/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivitySerializerException.java
+++ b/streams-pojo/src/main/java/org/apache/streams/exceptions/ActivitySerializerException.java
@@ -19,27 +19,28 @@
package org.apache.streams.exceptions;
/**
- * Created by sblackmon on 3/25/14.
+ * ActivitySerializerException is a typed exception appropriate when a valid Activity
+ * cannot be created from a given document.
*/
public class ActivitySerializerException extends Exception {
- public ActivitySerializerException() {
- // TODO Auto-generated constructor stub
- }
+ public ActivitySerializerException() {
+ // TODO Auto-generated constructor stub
+ }
- public ActivitySerializerException(String message) {
- super(message);
- // TODO Auto-generated constructor stub
- }
+ public ActivitySerializerException(String message) {
+ super(message);
+ // TODO Auto-generated constructor stub
+ }
- public ActivitySerializerException(Throwable cause) {
- super(cause);
- // TODO Auto-generated constructor stub
- }
+ public ActivitySerializerException(Throwable cause) {
+ super(cause);
+ // TODO Auto-generated constructor stub
+ }
- public ActivitySerializerException(String message, Throwable cause) {
- super(message, cause);
- // TODO Auto-generated constructor stub
- }
+ public ActivitySerializerException(String message, Throwable cause) {
+ super(message, cause);
+ // TODO Auto-generated constructor stub
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 43813d2..d64fd53 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
@@ -18,11 +18,12 @@
package org.apache.streams.jackson;
+import org.apache.streams.data.util.RFC3339Utils;
+
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.google.common.collect.Lists;
-import org.apache.streams.data.util.RFC3339Utils;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -38,42 +39,43 @@ import java.util.List;
* StreamsDateTimeDeserializer is a supporting class for
* @see {@link org.apache.streams.jackson.StreamsJacksonMapper}
*
+ * <p/>
* Converting date-time strings other than RFC3339 to joda DateTime objects requires
* additional formats to be provided when instantiating StreamsJacksonMapper.
*/
public class StreamsDateTimeDeserializer extends StdDeserializer<DateTime> implements Serializable {
- List<DateTimeFormatter> formatters = Lists.newArrayList();
+ List<DateTimeFormatter> formatters = Lists.newArrayList();
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsDateTimeDeserializer.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsDateTimeDeserializer.class);
- protected StreamsDateTimeDeserializer(Class<DateTime> dateTimeClass) {
- super(dateTimeClass);
- }
+ protected StreamsDateTimeDeserializer(Class<DateTime> dateTimeClass) {
+ super(dateTimeClass);
+ }
- protected StreamsDateTimeDeserializer(Class<DateTime> dateTimeClass, List<String> formats) {
- super(dateTimeClass);
- for( String format : formats ) {
- try {
- formatters.add(DateTimeFormat.forPattern(format));
- } catch (Exception e) {
- LOGGER.warn("Exception parsing format " + format);
- }
- }
+ protected StreamsDateTimeDeserializer(Class<DateTime> dateTimeClass, List<String> formats) {
+ super(dateTimeClass);
+ for ( String format : formats ) {
+ try {
+ formatters.add(DateTimeFormat.forPattern(format));
+ } catch (Exception ex) {
+ LOGGER.warn("Exception parsing format " + format);
+ }
}
+ }
- /**
- * Applies each additional format in turn, until it can provide a non-null DateTime
- */
- @Override
- public DateTime deserialize(JsonParser jpar, DeserializationContext context) throws IOException {
+ /**
+ * Applies each additional format in turn, until it can provide a non-null DateTime
+ */
+ @Override
+ public DateTime deserialize(JsonParser jpar, DeserializationContext context) throws IOException {
- DateTime result = RFC3339Utils.parseToUTC(jpar.getValueAsString());
- Iterator<DateTimeFormatter> iterator = formatters.iterator();
- while( result == null && iterator.hasNext()) {
- DateTimeFormatter formatter = iterator.next();
- result = formatter.parseDateTime(jpar.getValueAsString());
- }
- return result;
+ DateTime result = RFC3339Utils.parseToUTC(jpar.getValueAsString());
+ Iterator<DateTimeFormatter> iterator = formatters.iterator();
+ while ( result == null && iterator.hasNext()) {
+ DateTimeFormatter formatter = iterator.next();
+ result = formatter.parseDateTime(jpar.getValueAsString());
}
+ return result;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeFormat.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeFormat.java b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeFormat.java
index e9cab58..a3cc936 100644
--- a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeFormat.java
+++ b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeFormat.java
@@ -19,12 +19,13 @@
package org.apache.streams.jackson;
/**
- * Supplies a custom date-time format to StreamsJacksonModule
+ * Supplies a custom date-time format to StreamsJacksonModule.
*
+ * <p/>
* Implementations must have a no-argument constructor
*/
public interface StreamsDateTimeFormat {
- public String getFormat();
+ public String getFormat();
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeSerializer.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeSerializer.java b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeSerializer.java
index fff314d..0bae22f 100644
--- a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeSerializer.java
+++ b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsDateTimeSerializer.java
@@ -18,10 +18,11 @@
package org.apache.streams.jackson;
+import org.apache.streams.data.util.RFC3339Utils;
+
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
-import org.apache.streams.data.util.RFC3339Utils;
import org.joda.time.DateTime;
import java.io.IOException;
@@ -29,16 +30,16 @@ import java.io.Serializable;
/**
* StreamsDateTimeSerializer is a supporting class for
- * @see {@link org.apache.streams.jackson.StreamsJacksonMapper}
+ * @see {@link org.apache.streams.jackson.StreamsJacksonMapper}.
*/
public class StreamsDateTimeSerializer extends StdSerializer<DateTime> implements Serializable {
- protected StreamsDateTimeSerializer(Class<DateTime> dateTimeClass) {
- super(dateTimeClass);
- }
+ protected StreamsDateTimeSerializer(Class<DateTime> dateTimeClass) {
+ super(dateTimeClass);
+ }
- @Override
- public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
- jgen.writeString(RFC3339Utils.getInstance().format(value));
- }
+ @Override
+ public void serialize(DateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ jgen.writeString(RFC3339Utils.getInstance().format(value));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/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 2492b2f..6df9f85 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
@@ -18,6 +18,8 @@
package org.apache.streams.jackson;
+import org.apache.streams.pojo.StreamsJacksonMapperConfiguration;
+
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.PropertyAccessor;
@@ -28,7 +30,6 @@ 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;
@@ -36,99 +37,128 @@ import java.util.Map;
/**
* StreamsJacksonMapper is the recommended interface to jackson for any streams component.
*
+ * <p/>
* Date-time formats that must be supported can be specified with constructor arguments.
*
+ * <p/>
* If no Date-time formats are specified, streams will use reflection to find formats.
*/
public class StreamsJacksonMapper extends ObjectMapper {
- private static Map<StreamsJacksonMapperConfiguration, StreamsJacksonMapper> INSTANCE_MAP = Maps.newConcurrentMap();
-
- 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){
-
- StreamsJacksonMapper instance = new StreamsJacksonMapper(Lists.newArrayList(format));
-
- return instance;
-
+ private static Map<StreamsJacksonMapperConfiguration, StreamsJacksonMapper> INSTANCE_MAP = Maps.newConcurrentMap();
+
+ private StreamsJacksonMapperConfiguration configuration = new StreamsJacksonMapperConfiguration();
+
+ /**
+ * get default StreamsJacksonMapper.
+ * @return StreamsJacksonMapper
+ */
+ public static StreamsJacksonMapper getInstance() {
+ return getInstance(new StreamsJacksonMapperConfiguration());
+ }
+
+ /**
+ * get custom StreamsJacksonMapper.
+ * @param configuration StreamsJacksonMapperConfiguration
+ * @return StreamsJacksonMapper
+ */
+ 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(List<String> formats){
-
- StreamsJacksonMapper instance = new StreamsJacksonMapper(formats);
-
- return instance;
-
+ }
+
+ /**
+ * get custom StreamsJacksonMapper.
+ * @param format format
+ * @return StreamsJacksonMapper
+ */
+ @Deprecated
+ public static StreamsJacksonMapper getInstance(String format) {
+
+ StreamsJacksonMapper instance = new StreamsJacksonMapper(Lists.newArrayList(format));
+
+ return instance;
+
+ }
+
+ /**
+ * get custom StreamsJacksonMapper.
+ * @param formats formats
+ * @return StreamsJacksonMapper
+ */
+ @Deprecated
+ public static StreamsJacksonMapper getInstance(List<String> formats) {
+
+ StreamsJacksonMapper instance = new StreamsJacksonMapper(formats);
+
+ return instance;
+
+ }
+
+ /*
+ Use getInstance to get a globally shared thread-safe ObjectMapper,
+ rather than call this constructor. Reflection-based resolution of
+ date-time formats across all modules can be slow and should only happen
+ once per JVM.
+ */
+ protected StreamsJacksonMapper() {
+ super();
+ registerModule(new StreamsJacksonModule(configuration.getDateFormats()));
+ if ( configuration.getEnableScala()) {
+ registerModule(new DefaultScalaModule());
}
-
- /*
- Use getInstance to get a globally shared thread-safe ObjectMapper,
- rather than call this constructor. Reflection-based resolution of
- date-time formats across all modules can be slow and should only happen
- once per JVM.
- */
- protected StreamsJacksonMapper() {
- super();
- registerModule(new StreamsJacksonModule(configuration.getDateFormats()));
- if( configuration.getEnableScala())
- registerModule(new DefaultScalaModule());
- configure();
+ configure();
+ }
+
+ @Deprecated
+ public StreamsJacksonMapper(String format) {
+ super();
+ registerModule(new StreamsJacksonModule(Lists.newArrayList(format)));
+ if ( configuration.getEnableScala()) {
+ registerModule(new DefaultScalaModule());
}
-
- @Deprecated
- public StreamsJacksonMapper(String format) {
- super();
- registerModule(new StreamsJacksonModule(Lists.newArrayList(format)));
- if( configuration.getEnableScala())
- registerModule(new DefaultScalaModule());
- configure();
+ configure();
+ }
+
+ @Deprecated
+ public StreamsJacksonMapper(List<String> formats) {
+ super();
+ registerModule(new StreamsJacksonModule(formats));
+ if ( configuration.getEnableScala()) {
+ registerModule(new DefaultScalaModule());
}
-
- @Deprecated
- public StreamsJacksonMapper(List<String> formats) {
- super();
- 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();
- }
-
- public void configure() {
- disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
- configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
- configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, Boolean.TRUE);
- configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
- configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
- configure(DeserializationFeature.WRAP_EXCEPTIONS, Boolean.FALSE);
- configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, Boolean.TRUE);
- // If a user has an 'object' that does not have an explicit mapping, don't cause the serialization to fail.
- configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, Boolean.FALSE);
- configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, Boolean.FALSE);
- configure(SerializationFeature.WRITE_NULL_MAP_VALUES, Boolean.FALSE);
- setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.DEFAULT);
- setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ configure();
+ }
+
+ public StreamsJacksonMapper(StreamsJacksonMapperConfiguration configuration) {
+ super();
+ registerModule(new StreamsJacksonModule(configuration.getDateFormats()));
+ if ( configuration.getEnableScala()) {
+ registerModule(new DefaultScalaModule());
}
+ configure();
+ }
+
+ public void configure() {
+ disable(com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
+ configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, Boolean.FALSE);
+ configure(DeserializationFeature.FAIL_ON_INVALID_SUBTYPE, Boolean.TRUE);
+ configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, Boolean.TRUE);
+ configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, Boolean.TRUE);
+ configure(DeserializationFeature.WRAP_EXCEPTIONS, Boolean.FALSE);
+ configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, Boolean.TRUE);
+ // If a user has an 'object' that does not have an explicit mapping, don't cause the serialization to fail.
+ configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, Boolean.FALSE);
+ configure(SerializationFeature.WRITE_EMPTY_JSON_ARRAYS, Boolean.FALSE);
+ configure(SerializationFeature.WRITE_NULL_MAP_VALUES, Boolean.FALSE);
+ setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.DEFAULT);
+ setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonModule.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonModule.java b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonModule.java
index 4e02441..6696885 100644
--- a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonModule.java
+++ b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsJacksonModule.java
@@ -21,7 +21,6 @@ package org.apache.streams.jackson;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.joda.time.DateTime;
import org.joda.time.Period;
-
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
import org.reflections.util.ClasspathHelper;
@@ -35,46 +34,47 @@ import java.util.Set;
/**
* StreamsJacksonModule is a supporting class for
- * @see {@link org.apache.streams.jackson.StreamsJacksonMapper}
+ * @see {@link org.apache.streams.jackson.StreamsJacksonMapper}.
*
+ * <p/>
* RFC3339 dates are supported by default.
*/
public class StreamsJacksonModule extends SimpleModule {
- private final static Logger LOGGER = LoggerFactory.getLogger(StreamsJacksonModule.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(StreamsJacksonModule.class);
- public StreamsJacksonModule() {
- super();
+ public StreamsJacksonModule() {
+ super();
- Reflections reflections = new Reflections(new ConfigurationBuilder()
- .setUrls(ClasspathHelper.forPackage("org.apache.streams.jackson"))
- .setScanners(new SubTypesScanner()));
+ Reflections reflections = new Reflections(new ConfigurationBuilder()
+ .setUrls(ClasspathHelper.forPackage("org.apache.streams.jackson"))
+ .setScanners(new SubTypesScanner()));
- Set<Class<? extends StreamsDateTimeFormat>> dateTimeFormatClasses = reflections.getSubTypesOf(StreamsDateTimeFormat.class);
+ Set<Class<? extends StreamsDateTimeFormat>> dateTimeFormatClasses = reflections.getSubTypesOf(StreamsDateTimeFormat.class);
- List<String> dateTimeFormats = new ArrayList<>();
- for (Class dateTimeFormatClass : dateTimeFormatClasses) {
- try {
- dateTimeFormats.add(((StreamsDateTimeFormat) (dateTimeFormatClass.newInstance())).getFormat());
- } catch (Exception e) {
- LOGGER.warn("Exception getting format from " + dateTimeFormatClass);
- }
- }
+ List<String> dateTimeFormats = new ArrayList<>();
+ for (Class dateTimeFormatClass : dateTimeFormatClasses) {
+ try {
+ dateTimeFormats.add(((StreamsDateTimeFormat) (dateTimeFormatClass.newInstance())).getFormat());
+ } catch (Exception ex) {
+ LOGGER.warn("Exception getting format from " + dateTimeFormatClass);
+ }
+ }
- addSerializer(DateTime.class, new StreamsDateTimeSerializer(DateTime.class));
- addDeserializer(DateTime.class, new StreamsDateTimeDeserializer(DateTime.class, dateTimeFormats));
+ addSerializer(DateTime.class, new StreamsDateTimeSerializer(DateTime.class));
+ addDeserializer(DateTime.class, new StreamsDateTimeDeserializer(DateTime.class, dateTimeFormats));
- addSerializer(Period.class, new StreamsPeriodSerializer(Period.class));
- addDeserializer(Period.class, new StreamsPeriodDeserializer(Period.class));
- }
+ addSerializer(Period.class, new StreamsPeriodSerializer(Period.class));
+ addDeserializer(Period.class, new StreamsPeriodDeserializer(Period.class));
+ }
- public StreamsJacksonModule(List<String> formats) {
- super();
+ public StreamsJacksonModule(List<String> formats) {
+ super();
- addSerializer(DateTime.class, new StreamsDateTimeSerializer(DateTime.class));
- addDeserializer(DateTime.class, new StreamsDateTimeDeserializer(DateTime.class, formats));
+ addSerializer(DateTime.class, new StreamsDateTimeSerializer(DateTime.class));
+ addDeserializer(DateTime.class, new StreamsDateTimeDeserializer(DateTime.class, formats));
- addSerializer(Period.class, new StreamsPeriodSerializer(Period.class));
- addDeserializer(Period.class, new StreamsPeriodDeserializer(Period.class));
- }
+ addSerializer(Period.class, new StreamsPeriodSerializer(Period.class));
+ addDeserializer(Period.class, new StreamsPeriodDeserializer(Period.class));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodDeserializer.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodDeserializer.java b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodDeserializer.java
index 56487cd..b205a10 100644
--- a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodDeserializer.java
+++ b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodDeserializer.java
@@ -26,14 +26,16 @@ import org.joda.time.Period;
import java.io.IOException;
import java.io.Serializable;
-public class StreamsPeriodDeserializer extends StdDeserializer<Period> implements Serializable
-{
+/**
+ * StdDeserializer of Period.
+ */
+public class StreamsPeriodDeserializer extends StdDeserializer<Period> implements Serializable {
- protected StreamsPeriodDeserializer(Class<Period> dateTimeClass) {
- super(dateTimeClass);
- }
+ protected StreamsPeriodDeserializer(Class<Period> dateTimeClass) {
+ super(dateTimeClass);
+ }
- public Period deserialize(JsonParser jpar, DeserializationContext context) throws IOException {
- return Period.millis(jpar.getIntValue());
- }
+ public Period deserialize(JsonParser jpar, DeserializationContext context) throws IOException {
+ return Period.millis(jpar.getIntValue());
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodSerializer.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodSerializer.java b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodSerializer.java
index f72d337..3676615 100644
--- a/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodSerializer.java
+++ b/streams-pojo/src/main/java/org/apache/streams/jackson/StreamsPeriodSerializer.java
@@ -26,15 +26,17 @@ import org.joda.time.Period;
import java.io.IOException;
import java.io.Serializable;
-public class StreamsPeriodSerializer extends StdSerializer<Period> implements Serializable
-{
- protected StreamsPeriodSerializer(Class<Period> dateTimeClass) {
- super(dateTimeClass);
- }
+/**
+ * StdSerializer of Period.
+ */
+public class StreamsPeriodSerializer extends StdSerializer<Period> implements Serializable {
+
+ protected StreamsPeriodSerializer(Class<Period> dateTimeClass) {
+ super(dateTimeClass);
+ }
- @Override
- public void serialize(Period value, JsonGenerator jgen, SerializerProvider provider) throws IOException
- {
- jgen.writeString(Integer.toString(value.getMillis()));
- }
+ @Override
+ public void serialize(Period value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
+ jgen.writeString(Integer.toString(value.getMillis()));
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/test/java/org/apache/streams/pojo/test/ActivitySerDeTest.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/test/java/org/apache/streams/pojo/test/ActivitySerDeTest.java b/streams-pojo/src/test/java/org/apache/streams/pojo/test/ActivitySerDeTest.java
index fe00763..1bd8427 100644
--- a/streams-pojo/src/test/java/org/apache/streams/pojo/test/ActivitySerDeTest.java
+++ b/streams-pojo/src/test/java/org/apache/streams/pojo/test/ActivitySerDeTest.java
@@ -18,11 +18,12 @@
package org.apache.streams.pojo.test;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Activity;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
-import org.apache.streams.jackson.StreamsJacksonMapper;
-import org.apache.streams.pojo.json.Activity;
import org.junit.Test;
import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;
@@ -41,64 +42,64 @@ import java.util.Set;
*/
public class ActivitySerDeTest {
- private final static Logger LOGGER = LoggerFactory.getLogger(ActivitySerDeTest.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ActivitySerDeTest.class);
- private final static ObjectMapper MAPPER = StreamsJacksonMapper.getInstance();
+ private static final ObjectMapper MAPPER = StreamsJacksonMapper.getInstance();
- /**
- * Tests that all example activities can be loaded into Activity beans
- * @throws Exception
- */
- @Test
- public void testActivitySerDe() throws Exception {
+ /**
+ * Tests that all example activities can be loaded into Activity beans.
+ * @throws Exception Exception
+ */
+ @Test
+ public void testActivitySerDe() throws Exception {
- InputStream testActivityFolderStream = ActivitySerDeTest.class.getClassLoader()
- .getResourceAsStream("activitystreams-testdocs/activities");
- List<String> files = IOUtils.readLines(testActivityFolderStream, Charsets.UTF_8);
+ InputStream testActivityFolderStream = ActivitySerDeTest.class.getClassLoader()
+ .getResourceAsStream("activitystreams-testdocs/activities");
+ List<String> files = IOUtils.readLines(testActivityFolderStream, Charsets.UTF_8);
- for( String file : files) {
- LOGGER.info("File: " + file );
- LOGGER.info("Serializing: activities/" + file );
- InputStream testActivityFileStream = ActivitySerDeTest.class.getClassLoader()
- .getResourceAsStream("activities/" + file);
- Activity activity = MAPPER.readValue(testActivityFileStream, Activity.class);
- activity.setGenerator(null);
- activity.setLinks(new LinkedList<String>());
- String activityString = MAPPER.writeValueAsString(activity);
- LOGGER.info("Deserialized: " + activityString );
- assert( !activityString.contains("null") );
- assert( !activityString.contains("[]") );
- }
+ for ( String file : files) {
+ LOGGER.info("File: " + file );
+ LOGGER.info("Serializing: activities/" + file );
+ InputStream testActivityFileStream = ActivitySerDeTest.class.getClassLoader()
+ .getResourceAsStream("activities/" + file);
+ Activity activity = MAPPER.readValue(testActivityFileStream, Activity.class);
+ activity.setGenerator(null);
+ activity.setLinks(new LinkedList<String>());
+ String activityString = MAPPER.writeValueAsString(activity);
+ LOGGER.info("Deserialized: " + activityString );
+ assert ( !activityString.contains("null") );
+ assert ( !activityString.contains("[]") );
}
+ }
- /**
- * Tests that defined activity verbs have an example which can be loaded into
- * Activity beans and into verb-specific beans
- * @throws Exception
- */
- @Test
- public void testVerbSerDe() throws Exception {
+ /**
+ * Tests that defined activity verbs have an example which can be loaded into
+ * Activity beans and into verb-specific beans.
+ * @throws Exception Exception
+ */
+ @Test
+ public void testVerbSerDe() throws Exception {
- Reflections reflections = new Reflections(new ConfigurationBuilder()
- .setUrls(ClasspathHelper.forPackage("org.apache.streams.pojo.json"))
- .setScanners(new SubTypesScanner()));
- Set<Class<? extends Activity>> verbs = reflections.getSubTypesOf(Activity.class);
+ Reflections reflections = new Reflections(new ConfigurationBuilder()
+ .setUrls(ClasspathHelper.forPackage("org.apache.streams.pojo.json"))
+ .setScanners(new SubTypesScanner()));
+ Set<Class<? extends Activity>> verbs = reflections.getSubTypesOf(Activity.class);
- for( Class verbClass : verbs) {
- LOGGER.info("Verb: " + verbClass.getSimpleName() );
- Activity activity = (Activity) verbClass.newInstance();
- String verbName = activity.getVerb();
- String testfile = verbName.toLowerCase() + ".json";
- LOGGER.info("Serializing: activities/" + testfile );
- assert(ActivitySerDeTest.class.getClassLoader().getResource("activities/" + testfile) != null);
- InputStream testActivityFileStream = ActivitySerDeTest.class.getClassLoader()
- .getResourceAsStream("activities/" + testfile);
- assert(testActivityFileStream != null);
- activity = MAPPER.convertValue(MAPPER.readValue(testActivityFileStream, verbClass), Activity.class);
- String activityString = MAPPER.writeValueAsString(activity);
- LOGGER.info("Deserialized: " + activityString );
- assert( !activityString.contains("null") );
- assert( !activityString.contains("[]") );
- }
+ for ( Class verbClass : verbs) {
+ LOGGER.info("Verb: " + verbClass.getSimpleName() );
+ Activity activity = (Activity) verbClass.newInstance();
+ String verbName = activity.getVerb();
+ String testfile = verbName.toLowerCase() + ".json";
+ LOGGER.info("Serializing: activities/" + testfile );
+ assert (ActivitySerDeTest.class.getClassLoader().getResource("activities/" + testfile) != null);
+ InputStream testActivityFileStream = ActivitySerDeTest.class.getClassLoader()
+ .getResourceAsStream("activities/" + testfile);
+ assert (testActivityFileStream != null);
+ activity = MAPPER.convertValue(MAPPER.readValue(testActivityFileStream, verbClass), Activity.class);
+ String activityString = MAPPER.writeValueAsString(activity);
+ LOGGER.info("Deserialized: " + activityString );
+ assert ( !activityString.contains("null") );
+ assert ( !activityString.contains("[]") );
}
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/test/java/org/apache/streams/pojo/test/CustomDateTimeFormatTest.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/test/java/org/apache/streams/pojo/test/CustomDateTimeFormatTest.java b/streams-pojo/src/test/java/org/apache/streams/pojo/test/CustomDateTimeFormatTest.java
index eabde96..8fa927d 100644
--- a/streams-pojo/src/test/java/org/apache/streams/pojo/test/CustomDateTimeFormatTest.java
+++ b/streams-pojo/src/test/java/org/apache/streams/pojo/test/CustomDateTimeFormatTest.java
@@ -18,9 +18,10 @@
package org.apache.streams.pojo.test;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.streams.jackson.StreamsJacksonMapper;
import org.apache.streams.pojo.json.Activity;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
@@ -32,44 +33,44 @@ import static org.junit.Assert.assertEquals;
*/
public class CustomDateTimeFormatTest {
- @Test
- public void testCustomDateTimeFormatExplicit() {
- String format = "EEE MMM dd HH:mm:ss Z yyyy";
- String input = "Tue Jan 17 21:21:46 Z 2012";
- Long outputMillis = 1326835306000L;
- ObjectMapper mapper = StreamsJacksonMapper.getInstance(format);
- try {
- String json = "{\"published\":\"" + input + "\"}";
- Activity activity = mapper.readValue(json, Activity.class);
+ @Test
+ public void testCustomDateTimeFormatExplicit() {
+ String format = "EEE MMM dd HH:mm:ss Z yyyy";
+ String input = "Tue Jan 17 21:21:46 Z 2012";
+ Long outputMillis = 1326835306000L;
+ ObjectMapper mapper = StreamsJacksonMapper.getInstance(format);
+ try {
+ String json = "{\"published\":\"" + input + "\"}";
+ Activity activity = mapper.readValue(json, Activity.class);
- //Writes out value as a String including quotes
- Long result = activity.getPublished().getMillis();
+ //Writes out value as a String including quotes
+ Long result = activity.getPublished().getMillis();
- assertEquals(result, outputMillis);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail();
- }
+ assertEquals(result, outputMillis);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail();
}
+ }
- @Test
- public void testCustomDateTimeFormatReflection() {
- String input = "Tue Jan 17 21:21:46 Z 2012";
- Long outputMillis = 1326835306000L;
- ObjectMapper mapper = StreamsJacksonMapper.getInstance();
- try {
- String json = "{\"published\":\"" + input + "\"}";
- Activity activity = mapper.readValue(json, Activity.class);
+ @Test
+ public void testCustomDateTimeFormatReflection() {
+ String input = "Tue Jan 17 21:21:46 Z 2012";
+ Long outputMillis = 1326835306000L;
+ ObjectMapper mapper = StreamsJacksonMapper.getInstance();
+ try {
+ String json = "{\"published\":\"" + input + "\"}";
+ Activity activity = mapper.readValue(json, Activity.class);
- //Writes out value as a String including quotes
- Long result = activity.getPublished().getMillis();
+ //Writes out value as a String including quotes
+ Long result = activity.getPublished().getMillis();
- assertEquals(result, outputMillis);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail();
- }
+ assertEquals(result, outputMillis);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail();
}
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-streams/blob/5dffd5c3/streams-pojo/src/test/java/org/apache/streams/pojo/test/DateTimeSerDeTest.java
----------------------------------------------------------------------
diff --git a/streams-pojo/src/test/java/org/apache/streams/pojo/test/DateTimeSerDeTest.java b/streams-pojo/src/test/java/org/apache/streams/pojo/test/DateTimeSerDeTest.java
index 9fdda61..9a7a5ac 100644
--- a/streams-pojo/src/test/java/org/apache/streams/pojo/test/DateTimeSerDeTest.java
+++ b/streams-pojo/src/test/java/org/apache/streams/pojo/test/DateTimeSerDeTest.java
@@ -18,8 +18,9 @@
package org.apache.streams.pojo.test;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.streams.jackson.StreamsJacksonMapper;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Ignore;
@@ -35,47 +36,47 @@ import static org.junit.Assert.assertEquals;
*/
public class DateTimeSerDeTest {
- private final static Logger LOGGER = LoggerFactory.getLogger(DateTimeSerDeTest.class);
- private ObjectMapper mapper = StreamsJacksonMapper.getInstance();
+ private static final Logger LOGGER = LoggerFactory.getLogger(DateTimeSerDeTest.class);
+ private ObjectMapper mapper = StreamsJacksonMapper.getInstance();
- @Ignore
- @Test
- // this really needs to be able to pass...
- public void testActivityStringSer() {
- String input = "2012-01-17T21:21:46.000Z";
- try {
- DateTime output = mapper.readValue(input, DateTime.class);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail();
- }
+ @Ignore
+ @Test
+ // this really needs to be able to pass...
+ public void testActivityStringSer() {
+ String input = "2012-01-17T21:21:46.000Z";
+ try {
+ DateTime output = mapper.readValue(input, DateTime.class);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail();
}
+ }
- @Test
- public void testMillisDeser() {
- Long input = 1326856906000l;
- try {
- DateTime output = mapper.readValue(input.toString(), DateTime.class);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail();
- }
+ @Test
+ public void testMillisDeser() {
+ Long input = 1326856906000L;
+ try {
+ DateTime output = mapper.readValue(input.toString(), DateTime.class);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail();
}
+ }
- @Test
- public void testActivityStringDeser() {
- String output = "2012-01-17T21:21:46.000Z";
- long inputMillis = 1326835306000L;
- DateTime input;
- try {
- input = new DateTime(inputMillis);
- //Writes out value as a String including quotes
- String result = mapper.writeValueAsString(input);
- assertEquals(result.replace("\"", ""), output);
- } catch (Exception e) {
- e.printStackTrace();
- Assert.fail();
- }
+ @Test
+ public void testActivityStringDeser() {
+ String output = "2012-01-17T21:21:46.000Z";
+ long inputMillis = 1326835306000L;
+ DateTime input;
+ try {
+ input = new DateTime(inputMillis);
+ //Writes out value as a String including quotes
+ String result = mapper.writeValueAsString(input);
+ assertEquals(result.replace("\"", ""), output);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ Assert.fail();
}
+ }
}