Answer the question
In order to leave comments, you need to log in
I can't form a case class to correctly parse a JSON file. What am I doing wrong?
I'm using json4s
I have this JSON segment:
"properties": [
{
"name": "Name is here",
"values": [
[
"500/1000",
0
]
],
"displayMode": 2
}
],
I'm trying it represent it like this:
case class Property(
name: String,
values: Option[Option[(String, Int)]] = None,
displayMode:int
)
None is returned to values. Try without Option at all, tried with one, even tried with Seq. I don't understand what's wrong anymore. Can anyone enlighten? What am I doing wrong?
Answer the question
In order to leave comments, you need to log in
Wrapping Option in Option is generally superfluous. It seems to me that the question here is more about json deserialization. I have never worked with json4s, so I don’t know how (de)serialization works inside. If it is possible to customize serialization for specific types, then any object can be assembled (and disassembled). For example, in order to conveniently use pattern matching, you can use such a class, and, for example, using play-json , you can write custom serialization.
sealed trait Value
case class StringValue(s: String) extends Value
case class IntValue(i:Int) extends Value
case class Values(one: Value, two: Value)
case class Property(
name: String,
values: Values,
displayMode: Int
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question