This is something I’ve had to look up a few times, so I figured it’s time to write up something to ease the next time a bit.
First we need to include the Play JSON library itself to build.sbt
Using case classes seems to be the most used method of holding data to be encoded in JSON. So the next step is to configure out case class InventoryItem for reading and writing (decoding / encoding) into JSON with a companion object.
I’m using an example where we write a list of InventoryItems into JSON. Play JSON knows how to handle Lists automatically so no configuration is needed for that.
List of IntentoryItems would like something like this in JSON.
Reading JSON is from a string is a bit more involved than writing it.