Given below domain class, I want to convert the Blob data into Java object by deserializing the bytes. What is the approach to follow? Do I need to specify any converter to GORM to invoke it after fetching the data from DB?
class SpringMessage {
static mapping = {
datasource 'staging_oracle'
message type: 'blob', column: 'message_bytes'
createdDate type: Date, column: 'created_date'
}
static constraints = {
}
String messageId
Blob message //It holds the serialized bytes
Date createdDate
}
Ideally I do not want to have "Blob" property on the domain class. Instead I want to declare actual Java class type (ex: Foo message
) but hope to specify some type of converter in mapping. i.e
static mapping = {
message type:'blob', converter:FooDeserializer
}
Note the converter argument for message column in mapping. Is there such a feature in Grails? Or any other feature which allows me to do some post processing
after the data is fetched from GORM?
I use Grails 2.3.3.
As of now, I do the deserialization outside the grails generated findBy method. I was hoping that there would be some callback method which might be called by findByXXX implementations to do this convertion from Blob to java object.
ObjectInputStream is = new ObjectInputStream(springMessage.message.getBinaryStream())
Message<?> message = is.readObject()