Json Codec Backend
The purpose of this documentation is to give an explanation of how the Json Codec Backend works and how to use it. The Json Codec backend is a tool that generates encoders and decoders from a Morphir IR using the Circe JSON library. Codecs are generated in Scala
How to use the JSON Codec Backend
The first step to using the JSON Codec backend is to add the Circe JSON library to your project. This can be done in two ways:
- Add the Circe JSON dependency through your project build tool eg. Sbt, Mill etc.
morphir-jvmas a dependency to your project.
Generating Codecs from the IR
The backend is built to generate codecs for only types so when generating an IR , the
-t flag which specifies
--types-only should be used. Also, we want to add the
-f flag to use the old CLI make function.
To generate Codecs from the IR:
morphir-elm make -f -tto generate the IR.
morphir-elm gen -sto generate the codecs
- In the situation where you do not have
morphir-jvmas a dependency in your project, you have to add the
-cflag to copy dependencies from the
morphir-jvmproject. Complete command for this is
morphir-elm gen -s -c
Codecs are not generated for Function types in the morphir ir.