Reputation: 467
In cassandra table I put class, where one field is AnyContent type. I serialize it to array of bytes. Than I want get it from this column to my class. I can get it in method fromRow(row: Row)
only like
AnyContentAsText(TypeCodec.varchar().deserialize(body(row),
ProtocolVersion.NEWEST_SUPPORTED))
Only such way it compiles
But it returns AnyContent(AnyContentAsJson({"body":"value"})
and than it is hard to parse and get from it JSON value.
Maybe there are some straight way get it simply
Upvotes: 0
Views: 75
Reputation: 28511
The simple answer is that you don't, the strategy you are going for might not be the best idea. There is a lot of variation that is encapsulated inside AnyContent
and it's worth spending a little more time understanding what role that plays inside the Play Framework, it's a bit more complex than it meets the eye.
You would need to code from scratch a huge variety of decoders to allow you to re-create the original response encoded into AnyContent
, which to the best of my knowledge is not something that the framework offers.
Instead, what you are really after is a more domain centric approach where your database knows about your business objects, not about what HTTP framework you are using. In an ideal world, the database module and the web framework module should be completely separate inside your application, and the HTTP layer should depend on the database layer, not the other way around.
So I can be of further assistance, if would be useful to understand what you are trying to achieve. If you simply want to store JSON inside Cassandra blobs, then you already have JsonColumn
at your disposal for this very reason.
Have a look here for details.
Upvotes: 0