问题
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?
来源:https://stackoverflow.com/questions/57820366/ordering-of-fileds-on-the-generated-json-using-play-json-derived-codecs