MLHR-1749 added raw serializer for JSONObject and JSONArray
diff --git a/library/src/main/java/com/datatorrent/lib/util/JacksonObjectMapperProvider.java b/library/src/main/java/com/datatorrent/lib/util/JacksonObjectMapperProvider.java
index f520378..0ccb2d8 100644
--- a/library/src/main/java/com/datatorrent/lib/util/JacksonObjectMapperProvider.java
+++ b/library/src/main/java/com/datatorrent/lib/util/JacksonObjectMapperProvider.java
@@ -15,6 +15,7 @@
*/
package com.datatorrent.lib.util;
+import java.io.IOException;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
@@ -24,6 +25,8 @@
import org.codehaus.jackson.map.*;
import org.codehaus.jackson.map.module.SimpleModule;
import org.codehaus.jackson.map.ser.std.RawSerializer;
+import org.codehaus.jettison.json.JSONArray;
+import org.codehaus.jettison.json.JSONObject;
/**
* <p>JacksonObjectMapperProvider class.</p>
@@ -46,6 +49,8 @@
objectMapper.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, true);
objectMapper.configure(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS, false);
module.addSerializer(ObjectMapperString.class, new RawSerializer<Object>(Object.class));
+ module.addSerializer(JSONObject.class, new RawSerializer<Object>(Object.class));
+ module.addSerializer(JSONArray.class, new RawSerializer<Object>(Object.class));
objectMapper.registerModule(module);
}
@@ -64,4 +69,18 @@
module.addSerializer(clazz, serializer);
}
+ public JSONObject toJSONObject(Object o)
+ {
+ try {
+ return new JSONObject(this.getContext(null).writeValueAsString(o));
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public <T> T fromJSONObject(JSONObject json, Class<T> clazz) throws IOException
+ {
+ return this.getContext(null).readValue(json.toString(), clazz);
+ }
+
}
diff --git a/library/src/main/java/com/datatorrent/lib/util/PubSubMessage.java b/library/src/main/java/com/datatorrent/lib/util/PubSubMessage.java
index 1ef1f00..191acbb 100644
--- a/library/src/main/java/com/datatorrent/lib/util/PubSubMessage.java
+++ b/library/src/main/java/com/datatorrent/lib/util/PubSubMessage.java
@@ -26,6 +26,7 @@
public static final String TYPE_KEY = "type";
public static final String TOPIC_KEY = "topic";
public static final String DATA_KEY = "data";
+
public static final String INTERNAL_TOPIC_PREFIX = "_internal";
public static final String NUM_SUBSCRIBERS_SUFFIX = "numSubscribers";