streampipes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zehn...@apache.org
Subject [incubator-streampipes-extensions] branch dev updated: Update Json parser in ROS adapter
Date Fri, 13 Dec 2019 13:43:49 GMT
This is an automated email from the ASF dual-hosted git repository.

zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git


The following commit(s) were added to refs/heads/dev by this push:
     new 4fc0aaf  Update Json parser in ROS adapter
4fc0aaf is described below

commit 4fc0aafd200fe998d7f7399f33815f005764b70c
Author: Philipp Zehnder <zehnder@fzi.de>
AuthorDate: Fri Dec 13 14:43:29 2019 +0100

    Update Json parser in ROS adapter
---
 .../connect/adapters/ros/RosBridgeAdapter.java     | 32 +++++++---------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/streampipes-connect-adapters/streampipes-connect-adapter/src/main/java/org/apache/streampipes/connect/adapters/ros/RosBridgeAdapter.java
b/streampipes-connect-adapters/streampipes-connect-adapter/src/main/java/org/apache/streampipes/connect/adapters/ros/RosBridgeAdapter.java
index a6500d8..1d22372 100644
--- a/streampipes-connect-adapters/streampipes-connect-adapter/src/main/java/org/apache/streampipes/connect/adapters/ros/RosBridgeAdapter.java
+++ b/streampipes-connect-adapters/streampipes-connect-adapter/src/main/java/org/apache/streampipes/connect/adapters/ros/RosBridgeAdapter.java
@@ -18,6 +18,8 @@
 
 package org.apache.streampipes.connect.adapters.ros;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.JsonArray;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
@@ -48,10 +50,7 @@ import org.apache.streampipes.sdk.helpers.Labels;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 public class RosBridgeAdapter extends SpecificDataStreamAdapter  implements ResolvesContainerProvidedOptions
{
@@ -107,14 +106,19 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter  implements
Reso
 
         String topicType = getMethodType(this.ros, this.topic);
 
+        ObjectMapper mapper = new ObjectMapper();
         Topic echoBack = new Topic(ros, this.topic, topicType);
         echoBack.subscribe(new TopicCallback() {
             @Override
             public void handleMessage(Message message) {
 
-                InputStream stream = new ByteArrayInputStream(message.toString().getBytes(StandardCharsets.UTF_8));
 
-                jsonObjectParser.parse(stream, new ParseData());
+                try {
+                    Map<String, Object> result = mapper.readValue(message.toString(),
HashMap.class);
+                    adapterPipeline.process(result);
+                } catch (JsonProcessingException e) {
+                    e.printStackTrace();
+                }
             }
         });
 
@@ -229,22 +233,6 @@ public class RosBridgeAdapter extends SpecificDataStreamAdapter  implements
Reso
         return ob.get("type").getAsString();
     }
 
-    private class ParseData implements EmitBinaryEvent {
-
-        private JsonObjectFormat jsonObjectFormat;
-
-        public ParseData() {
-            this.jsonObjectFormat = new JsonObjectFormat();
-        }
-
-        @Override
-        public Boolean emit(byte[] event) {
-            Map<String, Object> result = this.jsonObjectFormat.parse(event);
-            adapterPipeline.process(result);
-            return true;
-        }
-    }
-
     private void getConfigurations(SpecificAdapterStreamDescription adapterDescription) {
         ParameterExtractor extractor = new ParameterExtractor(adapterDescription.getConfig());
         this.host = extractor.singleValue(ROS_HOST_KEY, String.class);


Mime
View raw message