Return-Path: X-Original-To: apmail-streams-dev-archive@minotaur.apache.org Delivered-To: apmail-streams-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0433E1121F for ; Sun, 11 May 2014 10:01:12 +0000 (UTC) Received: (qmail 10907 invoked by uid 500); 11 May 2014 10:01:11 -0000 Delivered-To: apmail-streams-dev-archive@streams.apache.org Received: (qmail 10861 invoked by uid 500); 11 May 2014 10:01:11 -0000 Mailing-List: contact dev-help@streams.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@streams.incubator.apache.org Delivered-To: mailing list dev@streams.incubator.apache.org Delivered-To: moderator for dev@streams.incubator.apache.org Received: (qmail 94963 invoked by uid 99); 10 May 2014 22:04:39 -0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org From: mfranklin To: dev@streams.incubator.apache.org Reply-To: dev@streams.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-streams pull request: STREAMS-60, STREAMS-70 Content-Type: text/plain Message-Id: <20140507140732.06108938023@tyr.zones.apache.org> Date: Wed, 7 May 2014 14:07:32 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Github user mfranklin commented on a diff in the pull request: https://github.com/apache/incubator-streams/pull/12#discussion_r12377982 --- Diff: streams-contrib/streams-processor-json/src/main/java/org/apache/streams/json/JsonPathFilter.java --- @@ -0,0 +1,149 @@ +package org.apache.streams.json; + +import com.fasterxml.jackson.core.JsonProcessingException; +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.fasterxml.jackson.datatype.jsonorg.JsonOrgModule; +import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; +import com.jayway.jsonpath.JsonPath; +import net.minidev.json.JSONArray; +import net.minidev.json.JSONObject; +import org.apache.commons.lang3.StringUtils; +import org.apache.streams.core.StreamsDatum; +import org.apache.streams.core.StreamsProcessor; +import org.apache.streams.jackson.StreamsJacksonMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +/** + * Created by sblackmon on 12/10/13. + */ +public class JsonPathFilter implements StreamsProcessor { + + public JsonPathFilter() { + System.out.println("creating JsonPathFilter"); + } + + private final static String STREAMS_ID = "JsonPathFilter"; + + private final static Logger LOGGER = LoggerFactory.getLogger(JsonPathFilter.class); + + private ObjectMapper mapper = new StreamsJacksonMapper(); + + private String pathExpression; + private JsonPath jsonPath; + private String destNodeName; + + @Override + public List process(StreamsDatum entry) { + + List result = Lists.newArrayList(); + + String json = null; + + ObjectNode document = null; + + LOGGER.debug("{} processing {}", STREAMS_ID); + + if( entry.getDocument() instanceof ObjectNode ) { + document = (ObjectNode) entry.getDocument(); + try { + json = mapper.writeValueAsString(document); + } catch (JsonProcessingException e) { + e.printStackTrace(); --- End diff -- Logger --- 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---