Remove jackson from feature-pooling-dmaap 98/75898/1
authorJim Hahn <jrh3@att.com>
Wed, 16 Jan 2019 16:06:28 +0000 (11:06 -0500)
committerJim Hahn <jrh3@att.com>
Wed, 16 Jan 2019 19:19:19 +0000 (14:19 -0500)
Modified code to use gson instead of jackson.

Change-Id: I5a1b2dacdc1801b1110154ed7c3c81e0713ef369
Issue-ID: POLICY-1431
Signed-off-by: Jim Hahn <jrh3@att.com>
12 files changed:
feature-pooling-dmaap/pom.xml
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/PoolingManagerImpl.java
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/Serializer.java
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/BucketAssignments.java
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Forward.java
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Leader.java
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/Message.java
feature-pooling-dmaap/src/main/java/org/onap/policy/drools/pooling/message/MessageWithAssignments.java
feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java
feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java
feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/SupportBasicMessageTester.java

index af18478..6ff89ed 100644 (file)
             <scope>provided</scope>
         </dependency>
 
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-core</artifactId>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-databind</artifactId>
-            <version>${jackson.version}</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>com.fasterxml.jackson.core</groupId>
-            <artifactId>jackson-annotations</artifactId>
-            <version>${jackson.version}</version>
-            <scope>provided</scope>
-        </dependency>
-
-        <dependency>
-            <groupId>com.fasterxml.jackson.datatype</groupId>
-            <artifactId>jackson-datatype-jsr310</artifactId>
-            <version>${jackson.version}</version>
-            <scope>provided</scope>
-        </dependency>
-
         <dependency>
             <groupId>ch.qos.logback</groupId>
             <artifactId>logback-classic</artifactId>
index 4db8fe3..b8fb641 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,8 +20,7 @@
 
 package org.onap.policy.drools.pooling;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import java.io.IOException;
+import com.google.gson.JsonParseException;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.Map;
@@ -348,7 +347,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
         try {
             dmaapMgr.setFilter(serializer.encodeFilter(filter));
 
-        } catch (JsonProcessingException e) {
+        } catch (JsonParseException e) {
             logger.error("failed to encode server-side filter for topic {}, {}", topic, filter, e);
 
         } catch (PoolingFeatureException e) {
@@ -393,7 +392,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
             String txt = serializer.encodeMsg(msg);
             dmaapMgr.publish(txt);
 
-        } catch (JsonProcessingException e) {
+        } catch (JsonParseException e) {
             logger.error("failed to serialize message for topic {} channel {}", topic, channel, e);
 
         } catch (PoolingFeatureException e) {
@@ -682,7 +681,7 @@ public class PoolingManagerImpl implements PoolingManager, TopicListener {
             Method meth = current.getClass().getMethod("process", msg.getClass());
             changeState((State) meth.invoke(current, msg));
 
-        } catch (IOException e) {
+        } catch (JsonParseException e) {
             logger.warn("failed to decode message for topic {}", topic, e);
 
         } catch (NoSuchMethodException | SecurityException e) {
index b37c33b..eee26ef 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.drools.pooling;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParseException;
+import java.util.HashMap;
 import java.util.Map;
+import org.onap.policy.drools.pooling.message.Forward;
+import org.onap.policy.drools.pooling.message.Heartbeat;
+import org.onap.policy.drools.pooling.message.Identification;
+import org.onap.policy.drools.pooling.message.Leader;
 import org.onap.policy.drools.pooling.message.Message;
+import org.onap.policy.drools.pooling.message.Offline;
+import org.onap.policy.drools.pooling.message.Query;
 
 /**
  * Serialization helper functions.
@@ -32,10 +39,36 @@ import org.onap.policy.drools.pooling.message.Message;
 public class Serializer {
 
     /**
-     * Used to encode & decode JSON messages sent & received, respectively, on
-     * the internal DMaaP topic.
+     * The message type is stored in fields of this name within the JSON.
      */
-    private final ObjectMapper mapper = new ObjectMapper();
+    private static final String TYPE_FIELD = "type";
+
+    /**
+     * Used to encode & decode JSON messages sent & received, respectively, on the
+     * internal DMaaP topic.
+     */
+    private final Gson gson = new Gson();
+
+    /**
+     * Maps a message subclass to its type.
+     */
+    private static final Map<Class<? extends Message>, String> class2type = new HashMap<>();
+
+    /**
+     * Maps a message type to the appropriate subclass.
+     */
+    private static final Map<String, Class<? extends Message>> type2class = new HashMap<>();
+
+    static {
+        class2type.put(Forward.class, "forward");
+        class2type.put(Heartbeat.class, "heartbeat");
+        class2type.put(Identification.class, "identification");
+        class2type.put(Leader.class, "leader");
+        class2type.put(Offline.class, "offline");
+        class2type.put(Query.class, "query");
+
+        class2type.forEach((clazz, type) -> type2class.put(type, clazz));
+    }
 
     /**
      * Constructor.
@@ -49,10 +82,10 @@ public class Serializer {
      * 
      * @param filter filter to be encoded
      * @return the filter, serialized as a JSON string
-     * @throws JsonProcessingException if it cannot be serialized
+     * @throws JsonParseException if it cannot be de-serialized
      */
-    public String encodeFilter(Map<String, Object> filter) throws JsonProcessingException {
-        return mapper.writeValueAsString(filter);
+    public String encodeFilter(Map<String, Object> filter) throws JsonParseException {
+        return gson.toJson(filter);
     }
 
     /**
@@ -60,10 +93,19 @@ public class Serializer {
      * 
      * @param msg message to be encoded
      * @return the message, serialized as a JSON string
-     * @throws JsonProcessingException if it cannot be serialized
+     * @throws JsonParseException if it cannot be de-serialized
      */
-    public String encodeMsg(Message msg) throws JsonProcessingException {
-        return mapper.writeValueAsString(msg);
+    public String encodeMsg(Message msg) throws JsonParseException {
+        JsonElement jsonEl = gson.toJsonTree(msg);
+
+        String type = class2type.get(msg.getClass());
+        if (type == null) {
+            throw new JsonParseException("cannot serialize " + msg.getClass());
+        }
+
+        jsonEl.getAsJsonObject().addProperty(TYPE_FIELD, type);
+
+        return gson.toJson(jsonEl);
     }
 
     /**
@@ -71,9 +113,23 @@ public class Serializer {
      * 
      * @param msg JSON string representing the message
      * @return the message
-     * @throws IOException if it cannot be serialized
+     * @throws JsonParseException if it cannot be serialized
      */
-    public Message decodeMsg(String msg) throws IOException {
-        return mapper.readValue(msg, Message.class);
+    public Message decodeMsg(String msg) throws JsonParseException {
+        JsonElement jsonEl = gson.fromJson(msg, JsonElement.class);
+
+        JsonElement typeEl = jsonEl.getAsJsonObject().get(TYPE_FIELD);
+        if (typeEl == null) {
+            throw new JsonParseException("cannot deserialize " + Message.class
+                            + " because it does not contain a field named " + TYPE_FIELD);
+
+        }
+
+        Class<? extends Message> clazz = type2class.get(typeEl.getAsString());
+        if (clazz == null) {
+            throw new JsonParseException("cannot deserialize " + typeEl);
+        }
+
+        return gson.fromJson(jsonEl, clazz);
     }
 }
index b5b6469..6be080f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
 
 package org.onap.policy.drools.pooling.message;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
@@ -33,7 +32,6 @@ import org.slf4j.LoggerFactory;
  */
 public class BucketAssignments {
 
-    @JsonIgnore
     private static final Logger logger = LoggerFactory.getLogger(BucketAssignments.class);
 
     /**
@@ -86,7 +84,6 @@ public class BucketAssignments {
      * 
      * @return the assignment leader
      */
-    @JsonIgnore
     public String getLeader() {
         if (hostArray == null) {
             return null;
@@ -110,7 +107,6 @@ public class BucketAssignments {
      * @param host host to be checked
      * @return {@code true} if the host has an assignment, {@code false} otherwise
      */
-    @JsonIgnore
     public boolean hasAssignment(String host) {
         if (hostArray == null) {
             return false;
@@ -130,7 +126,6 @@ public class BucketAssignments {
      * 
      * @return all of the hosts that have an assignment
      */
-    @JsonIgnore
     public Set<String> getAllHosts() {
         Set<String> set = new HashSet<>();
         if (hostArray == null) {
@@ -152,7 +147,6 @@ public class BucketAssignments {
      * @param hashCode hash code of the item whose assignment is desired
      * @return the assigned host, or {@code null} if the item has no assigned host
      */
-    @JsonIgnore
     public String getAssignedHost(int hashCode) {
         if (hostArray == null || hostArray.length == 0) {
             logger.error("no buckets have been assigned");
@@ -167,7 +161,6 @@ public class BucketAssignments {
      * 
      * @return the number of buckets
      */
-    @JsonIgnore
     public int size() {
         return (hostArray != null ? hostArray.length : 0);
     }
@@ -178,7 +171,6 @@ public class BucketAssignments {
      * 
      * @throws PoolingFeatureException if the assignments are invalid
      */
-    @JsonIgnore
     public void checkValidity() throws PoolingFeatureException {
         if (hostArray == null || hostArray.length == 0) {
             throw new PoolingFeatureException("missing hosts in message bucket assignments");
index 38acb8c..3c34e97 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
 
 package org.onap.policy.drools.pooling.message;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.drools.pooling.PoolingFeatureException;
 
@@ -141,14 +140,12 @@ public class Forward extends Message {
         this.requestId = requestId;
     }
 
-    @JsonIgnore
     public boolean isExpired(long minCreateTimeMs) {
         return (createTimeMs < minCreateTimeMs);
 
     }
 
     @Override
-    @JsonIgnore
     public void checkValidity() throws PoolingFeatureException {
 
         super.checkValidity();
index 7464a53..80149f6 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
 
 package org.onap.policy.drools.pooling.message;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
 import org.onap.policy.drools.pooling.PoolingFeatureException;
 
 /**
@@ -50,7 +49,6 @@ public class Leader extends MessageWithAssignments {
      * indeed the leader.
      */
     @Override
-    @JsonIgnore
     public void checkValidity() throws PoolingFeatureException {
 
         super.checkValidity();
index 215cdae..1de8786 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.drools.pooling.message;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonSubTypes;
-import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
-import com.fasterxml.jackson.annotation.JsonTypeInfo;
 import org.onap.policy.drools.pooling.PoolingFeatureException;
 
 /**
  * Messages sent on the internal topic.
  */
-@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type")
-@JsonSubTypes({@Type(value = Forward.class, name = "forward"), @Type(value = Heartbeat.class, name = "heartbeat"),
-                @Type(value = Identification.class, name = "identification"),
-                @Type(value = Leader.class, name = "leader"), @Type(value = Offline.class, name = "offline"),
-                @Type(value = Query.class, name = "query")})
 public class Message {
 
     /**
@@ -90,7 +81,6 @@ public class Message {
      * 
      * @throws PoolingFeatureException if the message is invalid
      */
-    @JsonIgnore
     public void checkValidity() throws PoolingFeatureException {
         if (source == null || source.isEmpty()) {
             throw new PoolingFeatureException("missing message source");
index 4a0b865..cfc3923 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
 
 package org.onap.policy.drools.pooling.message;
 
-import com.fasterxml.jackson.annotation.JsonIgnore;
 import org.onap.policy.drools.pooling.PoolingFeatureException;
 
 /**
@@ -65,7 +64,6 @@ public class MessageWithAssignments extends Message {
      * If there are any assignments, it verifies there validity.
      */
     @Override
-    @JsonIgnore
     public void checkValidity() throws PoolingFeatureException {
 
         super.checkValidity();
index 362c3b0..0cbc0e0 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,9 +28,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX;
 
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
+import com.google.gson.Gson;
+import com.google.gson.JsonParseException;
 import java.util.Arrays;
 import java.util.Deque;
 import java.util.IdentityHashMap;
@@ -113,21 +112,10 @@ public class EndToEndFeatureTest {
     private static final long STD_OFFLINE_PUB_WAIT_MS = 2;
     private static final long EVENT_WAIT_SEC = 15;
 
-    /**
-     * Used to decode events into a Map.
-     */
-    private static final TypeReference<TreeMap<String, String>> typeRef =
-                    new TypeReference<TreeMap<String, String>>() {};
-
     /**
      * Used to decode events from the external topic.
      */
-    private static final ThreadLocal<ObjectMapper> mapper = new ThreadLocal<ObjectMapper>() {
-        @Override
-        protected ObjectMapper initialValue() {
-            return new ObjectMapper();
-        }
-    };
+    private static final Gson mapper = new Gson();
 
     /**
      * Used to identify the current host.
@@ -281,9 +269,9 @@ public class EndToEndFeatureTest {
      */
     private static Object decodeEvent(String event) {
         try {
-            return mapper.get().readValue(event, typeRef);
+            return mapper.fromJson(event, TreeMap.class);
 
-        } catch (IOException e) {
+        } catch (JsonParseException e) {
             logger.warn("cannot decode external event", e);
             return null;
         }
index 01253fb..0d5b5e0 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,9 +28,8 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX;
 
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
+import com.google.gson.Gson;
+import com.google.gson.JsonParseException;
 import java.util.Arrays;
 import java.util.Deque;
 import java.util.IdentityHashMap;
@@ -108,22 +107,10 @@ public class FeatureTest {
     private static long stdPollMs = 2;
     private static long stdInterPollMs = 2;
     private static long stdEventWaitSec = 10;
-
-    /**
-     * Used to decode events into a Map.
-     */
-    private static final TypeReference<TreeMap<String, String>> typeRef =
-                    new TypeReference<TreeMap<String, String>>() {};
-
     /**
      * Used to decode events from the external topic.
      */
-    private static final ThreadLocal<ObjectMapper> mapper = new ThreadLocal<ObjectMapper>() {
-        @Override
-        protected ObjectMapper initialValue() {
-            return new ObjectMapper();
-        }
-    };
+    private static final Gson mapper = new Gson();
 
     /**
      * Used to identify the current context.
@@ -215,9 +202,9 @@ public class FeatureTest {
      */
     private static Object decodeEvent(String event) {
         try {
-            return mapper.get().readValue(event, typeRef);
+            return mapper.fromJson(event, TreeMap.class);
 
-        } catch (IOException e) {
+        } catch (JsonParseException e) {
             logger.warn("cannot decode external event", e);
             return null;
         }
@@ -722,7 +709,7 @@ public class FeatureTest {
 
                 return true;
 
-            } catch (IOException e) {
+            } catch (JsonParseException e) {
                 logger.warn("could not decode message: {}", message);
                 context.bumpDecodeErrors();
                 return false;
index 0b098c1..b51a18f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 package org.onap.policy.drools.pooling;
 
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -27,6 +28,7 @@ import static org.onap.policy.drools.pooling.state.FilterUtils.makeAnd;
 import static org.onap.policy.drools.pooling.state.FilterUtils.makeEquals;
 import static org.onap.policy.drools.pooling.state.FilterUtils.makeOr;
 
+import com.google.gson.JsonParseException;
 import java.util.Map;
 import java.util.TreeMap;
 import org.junit.Test;
@@ -92,6 +94,22 @@ public class SerializerTest {
 
         assertEquals(msg.getSource(), decoded.getSource());
         assertEquals(msg.getChannel(), decoded.getChannel());
+
+        // invalid subclass when encoding
+        assertThatThrownBy(() -> ser.encodeMsg(new Message() {})).isInstanceOf(JsonParseException.class)
+                        .hasMessageContaining("cannot serialize");
+
+        // missing type when decoding
+        final String enc2 = encoded.replaceAll("type", "other-field-name");
+
+        assertThatThrownBy(() -> ser.decodeMsg(enc2)).isInstanceOf(JsonParseException.class)
+                        .hasMessageContaining("does not contain a field named");
+
+        // invalid type
+        final String enc3 = encoded.replaceAll("query", "invalid-type");
+
+        assertThatThrownBy(() -> ser.decodeMsg(enc3)).isInstanceOf(JsonParseException.class)
+                        .hasMessage("cannot deserialize \"invalid-type\"");
     }
 
 }
index e30d78d..19e7ab0 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,9 +24,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
 import org.junit.Test;
 import org.onap.policy.drools.pooling.PoolingFeatureException;
+import org.onap.policy.drools.pooling.Serializer;
 
 /**
  * Superclass used to test subclasses of {@link Message}.
@@ -42,7 +42,7 @@ public abstract class SupportBasicMessageTester<T extends Message> {
     /**
      * Used to perform JSON serialization and de-serialization.
      */
-    public final ObjectMapper mapper = new ObjectMapper();
+    public final Serializer mapper = new Serializer();
 
     /**
      * The subclass of the type of Message being tested.
@@ -89,7 +89,13 @@ public abstract class SupportBasicMessageTester<T extends Message> {
     public final void testJsonEncodeDecode() throws Exception {
         T originalMsg = makeValidMessage();
 
-        Message msg = mapper.readValue(mapper.writeValueAsString(originalMsg), Message.class);
+        Message msg;
+        if (originalMsg.getClass() == Message.class) {
+            msg = originalMsg;
+        } else {
+            msg = mapper.decodeMsg(mapper.encodeMsg(originalMsg));
+        }
+        
         assertEquals(subclazz, msg.getClass());
 
         msg.checkValidity();