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?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---