title: Reading a JSON from DB with myBatis
body: <p>I have a column in DB I want to save it as JSON and retrieve it back.</p>
  
  <p>My approach is: </p>
  
  <p>I am saving it as <code>ClobTypeHandler</code> and trying to retrieve it as <code>ClobTypeHandler</code>.</p>
  
  <p>I am using Mybatis, However getting below error.</p>
  
  <pre><code>Could not set property 'idType' of 'class package.abc' with value '{"idNum":"123","text":"ENCkk-KZJTmN8Mr5jEims0rssRow8xaAnkOtl0RQHDth1ByVtshI7zQebtcogOvYM-gNo15DwwPmduaufk03CteqRL03cRyrG4%3B","key":"}P]H73}AF}TGB$OIDCYVIIB+VW{4TR)I?U}_`_ZXP[UY$BJNXV{U~/@!F%+SVMFYT/2IAXIOPB"}' Cause: java.lang.IllegalArgumentException: argument type mismatch
  </code></pre>
  
  <p>Below is the java layer and DB detail. </p>
  
  <pre><code>class abc{
  
      private JsonNode idType;
  
      public String getIdType() {
           return idType != null ? idType.toString():null;
      }
      public void setIdType(JsonNode idType) {
          this.idType = idType;
      }
  }
  </code></pre>
  
  <p>mapper.xml (Inserting to DB)</p>
  
  <pre><code>INSERT INTO CUSTOMER
      (&lt;include refid="common_customer_insert_columns"&gt;&lt;/include&gt;,id_type)        
   VALUES
      (&lt;include refid="common_customer_insert_fields"&gt;&lt;/include&gt;,&lt;include refid="cc_customer_insert_fields"&gt;&lt;/include&gt;,
          &lt;choose&gt; &lt;when test="abc.idType !=null"&gt;#{abc.idType,typeHandler= org.apache.ibatis.type.ClobTypeHandler}&lt;/when&gt;
                  &lt;otherwise&gt;''&lt;/otherwise&gt;&lt;/choose&gt;);
  </code></pre>
  
  <p>mapper.xml (while reading from DB)</p>
  
  <pre><code>&lt;resultMap&gt;
      &lt;result column="id_type" property="abc.idType" 
          typeHandler="org.apache.ibatis.type.ClobTypeHandler" /&gt;
  &lt;/resultMap&gt;
  </code></pre>
  
  <p>sample JSON value I am trying to save and retrieve:</p>
  
  <pre><code>"idType": {  
         "idNum": "123",  
         "text": "ENh-KZJTmN8Mr5jEims0rssRow8xaADth1ByVtshI7zQebtcogOvYM-gNo15DwwPmduaufk03CteqRLaVwF0b3cRyrG4%3D",  
         "key":"}P]H73}AF}TGB$OICQ*DCYVIIB+VW{4TR)I?U}_`_ZXP[UY$BJNXV{@!F%+SVMFYT/2IAXIOPB"  
        }  
  </code></pre>