A
A
Anatoly Evladov2016-05-22 22:10:25
Scala
Anatoly Evladov, 2016-05-22 22:10:25

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

1 answer(s)
A
Artem, 2016-05-22
@Visteras

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
                       )

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question