title: How to serialize JSON document using Messagepack (Cannot find template for class java.lang.Object)?
body: <p>I am planning to use Messagepack in our project. Currently, we are using JSON in our project and we are writing serialize JSON document into Cassandra. Now we are thinking to use Messagepack which is an efficient binary serialization format.</p>
  
  <p>I am trying to find a good example which shows me to use Messagepack on JSON document but I am not able to find it yet.</p>
  
  <p>Below is my main class code which will use Value class to make a JSON document using Jackson and then serialize the JSON using ObjectMapper.</p>
  
  <pre><code>public static void main(String[] args) {
  
      Map&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();
      properties.put("id", 123);
      properties.put("test", 200);
      properties.put("marks", 100);
  
      Value val = new Value();
      val.setProperties(properties);
  
      MessagePack msgpack = new MessagePack();
      // Serialize
      byte[] raw = msgpack.write(av);
  
      System.out.println(raw);
  
              // deserialize
      Value actual = new MessagePack().read(raw, Value.class);
  
      System.out.println(actual);
  }
  </code></pre>
  
  <p>Below is my Value class which is using Jackson to make a JSON document and will use ObjectMapper to serialize the document and also using Messagepack.</p>
  
  <pre><code>@JsonPropertyOrder(value = { "v" })
  @Message
  public class Value {
  
      private Map&lt;String, Object&gt; properties;
  
      /**
       * Default constructor.
       */
      @JsonCreator
      public Value() {
          properties = new HashMap&lt;String, Object&gt;();
      }
  
  
      /**
       * Gets the properties of this attribute value.
       * @return the properties of this attribute value.
       */
      @JsonProperty("v")
      public Map&lt;String, Object&gt; getProperties() {
          return properties;
      }
  
      /**
       * Sets the properties of this attribute value.
       * @param v the properties of this attribute value to set
       */
      @JsonProperty("v")
      public void setProperties(Map&lt;String, Object&gt; v) {
          properties = v;
      }
  
  
      @Override
      public String toString() {
          try {
              return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(this);
          } catch (Exception e) {
              // log exception
          }
  
          return ToStringBuilder.reflectionToString(this);
      }    
  }
  </code></pre>
  
  <p>But, I am not sure how to use Messagepack on this JSON document? Can anyone give me some example on this?   </p>
  
  <p>But I thought, let's give a try on this and whenever I am trying to use Messagepack like this in my above code-</p>
  
  <pre><code>    MessagePack msgpack = new MessagePack();
      // Serialize
      byte[] raw = msgpack.write(av);
  </code></pre>
  
  <p>I always get an exception like below-</p>
  
  <pre><code>Exception in thread "main" org.msgpack.MessageTypeException: Cannot find template for class java.lang.Object class.  Try to add @Message annotation to the class or call MessagePack.register(Type).
  </code></pre>
  
  <p>And I believe MessagePack doesn't allow users to serialize variables of java.lang.Object type but in my case, it is not possible to replace the type of properties to some primitive types.</p>
  
  <p>I am using Object in my HashMap and I need it to be like that..</p>