问题
I have a huge set of nested case classes for which I have added implicit formatters. Initially, I was hitting some ordering problems when I declared those formatters, but as soon as I was able to sort all the ordering out of the way, I get some other errors like:
Error:(57, 56) forward reference extends over definition of value zombType
implicit val varFmt: OFormat[Variant] = Json.format[Variant]
Here is my set of case classes which are defined in numerous different files:
In a package called commontypes, I have the following set of case classes:
sealed trait BuiltInType { def id: Int }
case class ZombieType (a: String, id: Int = 0) extends BuiltInType
case class BooleanType (a: Boolean, id: Int = 1) extends BuiltInType
case class ByteType (a: Byte, id: Int = 2) extends BuiltInType
case class UByteType (a: Byte, id: Int = 3) extends BuiltInType
case class Int16Type (a: Int, id: Int = 4) extends BuiltInType
case class UInt16Type (a: Int, id: Int = 5) extends BuiltInType
case class Int32Type (a: Int, id: Int = 6) extends BuiltInType
case class UInt32Type (a: Int, id: Int = 7) extends BuiltInType
case class Int64Type (a: Long, id: Int = 8) extends BuiltInType
case class UInt64Type (a: Long, id: Int = 9) extends BuiltInType
case class FloatType (a: Float, id: Int = 10) extends BuiltInType
case class DoubleType (a: Double, id: Int = 11) extends BuiltInType
case class StringType (a: String, id: Int = 12) extends BuiltInType
case class DateTimeType (a: Long, id: Int = 13) extends BuiltInType // FIXME: Wrong type used, fix it later
case class GuidType (a: UUID, id: Int = 14) extends BuiltInType
case class ByteStringType (a: Vector[Byte], id: Int = 15) extends BuiltInType
case class XmlElementType (a: String, id: Int = 16) extends BuiltInType
case class NodeIdType (a: NodeId, id: Int = 17) extends BuiltInType
case class ExpandedNodeIdType (a: NodeId, id: Int = 18) extends BuiltInType
case class StatusCodeType (a: StatusCode, id: Int = 19) extends BuiltInType
case class QualifiedNameType (a: QualifiedName, id: Int = 20) extends BuiltInType
case class LocalizedTextType (a: LocalizedText, id: Int = 21) extends BuiltInType
case class ExtensionObjectType (a: ExtensionObject, id: Int = 22) extends BuiltInType
case class DataValueType (a: DataValue, id: Int = 23) extends BuiltInType
case class VariantType (a: Variant, id: Int = 24) extends BuiltInType
case class DiagnosticInfoType (a: String, id: Int = 25) extends BuiltInType
In another package called headertypes, I have the following set of case classes defined:
sealed trait ExtensionObjectEncoding
case class ByteStringEncoding(bytes: Vector[Byte]) extends ExtensionObjectEncoding
case class XmlElementEncoding(xmlElement: String) extends ExtensionObjectEncoding
case class ExtensionObject(
encodingTypeId: NodeId,
encodedBody: ExtensionObjectEncoding
)
case class DataValue(
value: Variant,
status: StatusCode,
sourceTime: Long, // TODO: Need to be a Datetime type
sourcePicoseconds: Int,
serverTime: Long, // TODO: Need to be a Datetime type
serverPicoseconds: Int
)
case class KeyValueProperty(
qName: QualifiedName,
value: Variant
)
sealed trait VariantData
case class SimpleOrder(rows: Vector[BuiltInType]) extends VariantData
case class HigherOrder(matrices: Vector[VariantData]) extends VariantData
Here is the GitHub project and I have declared all the implicit formats in a file called DataSetMetaDataParserSpec which is a test that I'm writing!
Any idea how I can resolve this error?
来源:https://stackoverflow.com/questions/57685264/play-json-error-with-many-nested-case-classes