Play JSON serialisation
rowlandwatkins opened this issue · comments
Hi,
Are there any tricks I might be missing for JSON serialisation for domain objects retrieved using slick-additions?
If we take the Phones domain class example. When I try to do the following:
implicit val phoneFormat = Json.format[Phone]
....
def phones = DBAction{ implicit rs =>
Ok(toJson(Phones.list))
}
I get the following compilation error:
No Json serializer found for type List[models.Phones#TableElementType]. Try to implement an implicit Writes or Format for this type.
Previously, when using the Play JSON converters I could simply provide the case class. Do you know any easy way to do this?
Cheers,
Rowland
So it looks like Phones.list was returning List(SavedEntity(key, value[Phone]))).
I've now mapped that list to a Phone with an id, so now JSON serialisation works (still need a JSON writes implicit though).
Hi, apologies, somehow I don't think I noticed this.
Glad you got it working in the end. I'm not familiar with Play JSON but I suppose you could also provide a de/serializer for KeyedEntity.
I guess this issue should be closed? (Feel free to reopen it if I missed something.)