You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/06/07 13:54:14 UTC

svn commit: r1132962 - /activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/JsonCodec.java

Author: chirino
Date: Tue Jun  7 11:54:14 2011
New Revision: 1132962

URL: http://svn.apache.org/viewvc?rev=1132962&view=rev
Log:
Set the context classloader so that the Json can get properly decoded.

Modified:
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/JsonCodec.java

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/JsonCodec.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/JsonCodec.java?rev=1132962&r1=1132961&r2=1132962&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/JsonCodec.java (original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/JsonCodec.java Tue Jun  7 11:54:14 2011
@@ -16,17 +16,11 @@
  */
 package org.apache.activemq.apollo.dto;
 
-import org.codehaus.jackson.JsonParseException;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.fusesource.hawtbuf.Buffer;
 import org.fusesource.hawtbuf.ByteArrayOutputStream;
 
-import javax.xml.bind.JAXBException;
-import javax.xml.stream.XMLStreamException;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Properties;
 
 /**
  *
@@ -37,7 +31,13 @@ public class JsonCodec {
     private static ObjectMapper mapper = new ObjectMapper();
 
     static public <T> T decode(Buffer buffer, Class<T> type) throws IOException {
-        return mapper.readValue(buffer.in(), type);
+        ClassLoader original = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(JsonCodec.class.getClassLoader());
+        try {
+            return mapper.readValue(buffer.in(), type);
+        } finally {
+            Thread.currentThread().setContextClassLoader(original);
+        }
     }
 
     static public Buffer encode(Object value) throws IOException {