0

To solve one of my complex case classes to JSON mapping, I used the play json dereived codecs library. It works and produces the JSON structure that I want, but the order in which the elements are present in the JSON is nos something that I would want!

For example., here is my case class:

case class DataSetMetaData(
    dataSetWriterId: Int,
    dataTypeSchemaHeader: DataTypeSchemaHeader,
    name: String,
    description: LocalizedText,
    fields: Seq[FieldMetaData],
    dataSetClassId: UUID,
    configVersion: ConfigVersion,
    status: StatusCode
  )

The resulting JSON has a structure like this:

{"name":"TEST_Dataset","description":{},"dataSetClassId":"00000000-7e77-7f33-3138-3138313817fc","configVersion":{"majorVersion":6162,"minorVersion":6162},"status":{"value":0},....

As it can be seen that I want it to first have the dataSetWriterId field instead of the name field. Is this something that can be done to change the order in which the fields are represented in the resulting JSON?

joesan
  • 13,963
  • 27
  • 95
  • 232
  • I'm not sure if this is possible as JSON is unordered by definition, See https://stackoverflow.com/a/4920304/2750966 – pme Sep 06 '19 at 11:44
  • Hmm! Ok so that is straight from the Spec! But nevertheless I would assume that the Scala library handling this could make some adjustments to preserve the order? – joesan Sep 06 '19 at 11:47

0 Answers0