I\'m developing a Spring Data JPA application, and I\'ve created an AttributeConverter
class in order to save an ArrayList
of objects as JSON in a
You can inject a bean(@Component, @Service, @Repository) inside an AttributeConverter using static properties
Setps:
Basically, the code should look like this...
//Step 1
@Component
@Converter
@Configurable
public class MyAttributeConverter implements AttributeConverter {
//Where: X = the type of the entity attribute and Y = the type of the database column
//Step 2
private static MyRepository myRepository;
//Step 3
@Autowired
public void initMyRepository(MyRepository myRepository){
MyAttributeConverter.myRepository = myRepository;
}
//Step 4
Y convertToDatabaseColumn(X attribute){//TODO implement method}
X convertToEntityAttribute(Y dbData){//TODO implement method}
}
I hope it can help!!!