For saving a list with json format in postgresql I use com.vladmihalcea:hibernate-types-52
in Spring boot 2 as follow:
@Entity
@TypeDefs({
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
public class Profile {
...
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private List<String> locations;
// getters & setters
}
With this, All things are OK and I can save locations as json in postgresql. But I want to save locations as class inheritance structure. The classes are as follow:
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.PROPERTY, property = "type")
@JsonSubTypes({
@JsonSubTypes.Type(value = SubClass1.class, name = "subClass1"),
@JsonSubTypes.Type(value = SubClass2.class, name = "subClass2")
})
public abstract class MyClass {
private String name;
// getters & setters
}
public class SubClass1 extends MyClass {
private String prop;
// getters & setters
}
public class SubClass2 extends MyClass {
...
}
public class LocationList extends ArrayList<MyClass>{}
Now I want to save this structure in a json from class Profile as somthing bellow:
public class Profile {
...
@Type(type = "jsonb")
@Column(columnDefinition = "jsonb")
private LocationList locations;
// getters & setters
}
When I create an instance of Profile and without saving, return it to client, It's fine, but when I want to save to postgresql db, it occure error and error message is:
java.lang.IllegalArgumentException: Cannot create TypeBindings for class LocationList with 1 type parameter: class expects 0
How can I fix it?