title: ERROR: column is of type json but expression is of type character varying in Hibernate
body: <p>I need to map two columns of entity class as json in postgres using spring data jpa. After reading multiple stackoverflow posts and baeldung post ,</p>
  <p><a href="https://stackoverflow.com/questions/25738569/how-to-map-a-map-json-column-to-java-object-with-jpa">How to map a map JSON column to Java Object with JPA</a></p>
  <p><a href="https://www.baeldung.com/hibernate-persist-json-object" rel="noreferrer">https://www.baeldung.com/hibernate-persist-json-object</a></p>
  <p>I did configuration as below. However, I am facing error &quot;<strong>ERROR: column &quot;headers&quot; is of type json but expression is of type character varying</strong>&quot;</p>
  <p>Please provide some pointer to resolve this issue.</p>
  <p>I have an entity class as below</p>
  <pre><code>@Entity
  @Data
  @SuperBuilder
  @NoArgsConstructor
  @AllArgsConstructor
  public class Task {
      @Id
      @GeneratedValue(strategy = IDENTITY)
      private Integer id;
      
      private String url;
      private String httpMethod;
  
      @Convert(converter = HashMapConverter.class)
      @Column(columnDefinition = &quot;json&quot;)
      private Map&lt;String, String&gt; headers;
  
      @Convert(converter = HashMapConverter.class)
      @Column(columnDefinition = &quot;json&quot;)
      private Map&lt;String, String&gt; urlVariables;
  }
  </code></pre>
  <p>I have created a test class to test if entity is persisted or not. On running this junit, below test case is failing with error as below</p>
  <p><a href="https://i.stack.imgur.com/c0Z1k.png" rel="noreferrer"><img src="https://i.stack.imgur.com/c0Z1k.png" alt="enter image description here" /></a></p>
  <pre><code>@SpringBootTest
  class TaskRepositoryTest {
  
      private static Task randomTask = randomTask();
  
      @Autowired
      private TaskRepository taskRepository;
  
      @BeforeEach
      void setUp() {
          taskRepository.deleteAll();
          taskRepository.save(randomTask);
      }
  
      public static Task randomTask() {
          return randomTaskBuilder().build();
      }
  
      public static TaskBuilder randomTaskBuilder() {
          Map&lt;String,String&gt; headers = new HashMap&lt;&gt;();
          headers.put(randomAlphanumericString(10),randomAlphanumericString(10));
  
          Map&lt;String,String&gt; urlVariables = new HashMap&lt;&gt;();
          urlVariables.put(randomAlphanumericString(10),randomAlphanumericString(10));
  
          return builder()
                  .id(randomPositiveInteger())
                  .httpMethod(randomAlphanumericString(10))
                  .headers(headers)
                  .urlVariables(urlVariables)
                  .url(randomAlphanumericString(10)));
      }
  }
  </code></pre>
  <p>Using liquibase, I have created table in postgres DB and I could see column datatype as json.</p>
  <pre><code>databaseChangeLog:
    - changeSet:
        id: 1
        author: abc
        changes:
          - createTable:
              tableName: task
              columns:
                - column:
                    name: id
                    type: int
                    autoIncrement: true
                    constraints:
                      primaryKey: true
                - column:
                    name: url
                    type: varchar(250)
                    constraints:
                      nullable: false
                      unique: true
                - column:
                    name: http_method
                    type: varchar(50)
                    constraints:
                      nullable: false
                - column:
                    name: headers
                    type: json
                - column:
                    name: url_variables
                    type: json
        rollback:
          - dropTable:
              tableName: task
  </code></pre>