Ordering of Fileds on the Generated JSON using Play JSON Derived Codecs

冷暖自知 提交于 2019-12-11 15:10:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!