[
https://issues.apache.org/jira/browse/STREAMS-212?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14236222#comment-14236222
]
ASF GitHub Bot commented on STREAMS-212:
----------------------------------------
Github user robdouglas commented on a diff in the pull request:
https://github.com/apache/incubator-streams/pull/149#discussion_r21405155
--- Diff:
streams-components/streams-converters/src/main/java/org/apache/streams/converter/TypeConverterProcessor.java
---
@@ -0,0 +1,91 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.streams.converter;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import org.apache.streams.core.StreamsDatum;
+import org.apache.streams.core.StreamsProcessor;
+import org.apache.streams.jackson.StreamsJacksonMapper;
+import org.apache.streams.pojo.json.Activity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * TypeConverterProcessor converts between String json and
jackson-compatible POJO objects.
+ *
+ * Activity is one supported jackson-compatible POJO, so JSON String and
objects with structual similarities
+ * to Activity can be converted to Activity objects.
+ *
+ * However, conversion to Activity should probably use {@link
org.apache.streams.converter.ActivityConverterProcessor}
+ *
+ */
+public class TypeConverterProcessor implements StreamsProcessor,
Serializable {
+
+ private final static Logger LOGGER =
LoggerFactory.getLogger(TypeConverterProcessor.class);
+
+ private List<String> formats = Lists.newArrayList();
+
+ protected ObjectMapper mapper;
+
+ protected Class outClass;
+
+ public TypeConverterProcessor(Class outClass) {
+ this.outClass = outClass;
+ }
+
+ public TypeConverterProcessor(Class outClass, List<String> formats) {
+ this(outClass);
+ this.formats = formats;
+ }
+
+ @Override
+ public List<StreamsDatum> process(StreamsDatum entry) {
+
+ List<StreamsDatum> result = Lists.newLinkedList();
+ Object inDoc = entry.getDocument();
+
+ Object outDoc = TypeConverterUtil.convert(inDoc, outClass, mapper);
+
+ if( outDoc != null ) {
+ entry.setDocument(outDoc);
+ result.add(entry);
+ }
+
+ return result;
+ }
+
+ @Override
+ public void prepare(Object configurationObject) {
+ if( formats.size() > 0 )
--- End diff --
Small Nit: Could you surround these lines with braces?
> Generic Type Converter Processor
> --------------------------------
>
> Key: STREAMS-212
> URL: https://issues.apache.org/jira/browse/STREAMS-212
> Project: Streams
> Issue Type: Sub-task
> Reporter: Steve Blackmon
>
> Build a utility processor that will handle conversion to/from any
> jackson-compatible POJOs and/or JSON String representations. Demonstrate how
> to refactor existing components and streams to use this processor rather than
> replicating these common routines.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)