title: java.lang.IllegalArgumentException: The given string value: { "In last 7 days" : 19 } cannot be transformed to Json object
body: <p>Hi I have a json field in my postgresql table and I am using criteria api to read it's value but I am getting above error message. I have followed the steps mentioned in <a href="https://vladmihalcea.com/map-string-jpa-property-json-column-hibernate/" rel="nofollow noreferrer">https://vladmihalcea.com/map-string-jpa-property-json-column-hibernate/</a></p>
  
  <p>My code - </p>
  
  <p>pojo</p>
  
  <pre><code>@Entity
  @Table(name = "table_name", schema = "test")
  @TypeDef(
          name = "jsonb",
          typeClass = JsonBinaryType.class
  )
  public class Test implements Serializable {
      @Type(type = "jsonb")
      @Column(name = "details", columnDefinition = "jsonb")
      MyClass myclass;
  
  } 
  </code></pre>
  
  <p>MyClass: </p>
  
  <pre><code>public class MyClass implements Serializable {
      private String days;
      private String value;
  
      public String getDays() {
          return days;
      }
  
      public void setDays(String days) {
          this.days = days;
      }
  
      public String getValue() {
          return value;
      }
  
      public void setValue(String value) {
          this.value = value;
      }
  
      @Override
      public String toString() {
          return '{' + '"' + days + '"' + ':' + value + '}';
      }
  }
  </code></pre>
  
  <p>MyDTO - </p>
  
  <pre><code>public class MyDTO {
      @JsonProperty("details")
      MyClass myClass;
  
  }
  
  </code></pre>
  
  <p>criteria API : </p>
  
  <pre><code>CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
  CriteriaQuery&lt;Object[]&gt; criteriaQuery = criteriaBuilder.createQuery(Object[].class);
  Root&lt;Test&gt; test = criteriaQuery.from(Test.class);
  criteriaQuery.where(criteriaBuilder.equal(criteriaBuilder.lower(test.get("test_id")), testId.toLowerCase()));
  criteriaQuery.select(test.get("myclass"));
  List&lt;Object[]&gt; result = entityManager.createQuery(criteriaQuery).getResultList();
  
  </code></pre>
  
  <p>error stacktrace: </p>
  
  <pre><code>Severe Error: 
  java.lang.IllegalArgumentException: The given string value: { "In last 7 days" : 19 } cannot be transformed to Json object
      at com.vladmihalcea.hibernate.type.json.internal.JacksonUtil.fromString(JacksonUtil.java:20)
      at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.fromString(JsonTypeDescriptor.java:52)
      at com.vladmihalcea.hibernate.type.json.internal.JsonTypeDescriptor.wrap(JsonTypeDescriptor.java:75)
      at com.vladmihalcea.hibernate.type.json.internal.AbstractJsonSqlTypeDescriptor$1.doExtract(AbstractJsonSqlTypeDescriptor.java:34)
      at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:47)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:257)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
      at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:243)
      at org.hibernate.loader.hql.QueryLoader.getResultRow(QueryLoader.java:457)
      at org.hibernate.loader.hql.QueryLoader.getResultColumnOrRow(QueryLoader.java:440)
      at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:775)
      at org.hibernate.loader.Loader.processResultSet(Loader.java:1008)
      at org.hibernate.loader.Loader.doQuery(Loader.java:964)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
      at org.hibernate.loader.Loader.doList(Loader.java:2838)
      at org.hibernate.loader.Loader.doList(Loader.java:2820)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2652)
      at org.hibernate.loader.Loader.list(Loader.java:2647)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:506)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:396)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:219)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1404)
      at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1562)
      at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1530)
      at org.hibernate.query.Query.getResultList(Query.java:165)
      at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:76)
      at com.test.getTestDetail(ServiceV2.java:108)
      at com.test.ControllerV2.fetchDetail(ControllerV2.java:77)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
      at org.springframework.test.web.servlet.TestDispatcherServlet.service(TestDispatcherServlet.java:71)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
      at org.springframework.mock.web.MockFilterChain$ServletFilterProxy.doFilter(MockFilterChain.java:166)
      at org.springframework.mock.web.MockFilterChain.doFilter(MockFilterChain.java:133)
      at org.springframework.test.web.servlet.MockMvc.perform(MockMvc.java:182)
      at com.test.ControllerV2Test.testDetails(ControllerV2Test.java:153)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
      at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
      at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
      at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
      at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
      at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  `
  </code></pre>