This repository contains shared code used by targeting, frontend, and MAPI to create and process targeted campaigns.
- Play 3.0 : use
libraryDependencies += "com.gu.targeting-client" %% "client-play-json-v30" % "[maven version number]"
- Play 2.8 : use
libraryDependencies += "com.gu.targeting-client" %% "client-play-json-v28" % "[maven version number]"
Campaign types are expressed as a set of fields. To add a new set of fields edit the Fields.scala file in the following way. I'll use the example set of a charity drive campaign.
- Decide what your fields* are going to be. In my example I'll say I want a charity name, and website url.
- Create a new
case class
representing the fields and ensure this classextends Fields
. In keeping with the naming conventions we'll call our exampleCharityDriveFields
. - Select a type string for your new Fields, this will be set to the
_type
field in the resulting JSON. Make sure you add it to theallFields
member. - Now you need to make sure you can serialize and deserialize to the correct types. You can follow the pattern in the file or find someone who has done this before using the git blame feature.
fieldWrites
takes in aFields
, finds the subtype, and selects the correct formatter to write the JSON.fieldReads
is similar except it searches a block of JSON for atype
variable and uses it to select the correct subclass ofFields
- Add the new case class to the match on the file Campaign.scala in the function getFieldsType.
- You should be done now! Ensure the library still compiles and then continue onto the following section on how to publish a new version.
* Note: you cannot have a variable called
_type
since the JSON serializers use this string in order to know what type of field is being read.
This repo uses gha-scala-library-release-workflow
to automate publishing releases (both full & preview releases) - see
Making a Release.