I am trying to parse this json object and I ran a unit test and I got this error Error: Error when parsing result of 'listdescriptors': {"obj":[{"msg":["error.expected.jsarray"],"args":[]}]}! [info] at org.bitcoins.rpc.client.common.Client.parseResult(Client.scala:455). I think the problem may be that I'm parsing the json file into a case class incorectly.
Result:
{ (json object)
"wallet_name" : "str", (string) Name of wallet this operation was performed on
"descriptors" : [ (json array) Array of descriptor objects
{ (json object)
"desc" : "str", (string) Descriptor string representation
"timestamp" : n, (numeric) The creation time of the descriptor
"active" : true|false, (boolean) Activeness flag
"internal" : true|false, (boolean, optional) Whether this is an internal or external descriptor; defined only for active descriptors
"range" : [ (json array, optional) Defined only for ranged descriptors
n, (numeric) Range start inclusive
n (numeric) Range end inclusive
],
"next" : n (numeric, optional) The next index to generate addresses from; defined only for ranged descriptors
},
...
]
}
object JsonSerializers {
implicit val descriptorsClassReads: Reads[descriptorsClass] =
Json.reads[descriptorsClass]
implicit val listDescriptorsReads: Reads[listDescriptorsResult] =
Json.reads[listDescriptorsResult]
sealed abstract class WalletResult
case class listDescriptorsResult(
wallet_name: String,
descriptors: Vector[descriptorsClass]
) extends WalletResult
case class descriptorsClass(
desc: String,
timestamp: ZonedDateTime,
active: Boolean,
internal: Boolean,
range: Array[(Int, Int)],
next: Int
) extends WalletResult
Arrayas case class field, as it's mutable, and so violate the immutability contract of case class. Class should not be named with an initial lowercase asdescriptorClass. Instead of an empty abstract class, rather use a trait. There is no need to violate the Scala naming to support snake_case naming in the JSON representation.