1

I have this field

   @Type(type = "json")
@Column(columnDefinition = "json")
private Map<String, String> businessHours;

and this is on top of my class

@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonType.class)//this is error
})

and this is migartion

 alter table properties alter column business_houres type json USING business_hours::json;

but it can't understand JsonType it is red

1 Answer 1

2

You should be using JsonBinaryType.class or JsonStringType.class for the type json and JsonType.class is not a type that comes out of the box.

@TypeDefs({
  @TypeDef(name = "json", typeClass = JsonBinaryType.class)
})
public class BaseEntity {
   @Type(type = "json")
   @Column(columnDefinition = "json")
   private BusinessHours businessHours;
}

You can create a wrapper class that stores the businessHours as follows:

public class BusinessHours implements Serializable {
    private Map<String, String> businessHours; 
}

Sign up to request clarification or add additional context in comments.

9 Comments

I agree but after set some map and then save it gives me this error. ERROR: column "business_hours" is of type json but expression is of type character varying Hint: You will need to rewrite or cast the expression.
@JackNickelson I have updated my answer can you see if using the wrapper class with JsonBinaryType.class solves your question?
I don't need binary it has ordering but now i set String one but after setting some map and saving it it gives this error ERROR: column "business_hours" is of type json but expression is of type character varying Hint: You will need to rewrite or cast the expression.
@JackNickelson can you try with creating BusinessHours.java with the map instead and see if that helps?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.