0

I have the following piece of code:

def fromString[T <: AnyRef](str: String)(implicit m: Manifest[T]): T = {
    val json = parse(str)
    json.extract[T](formats,m)
}

I also have a case class that is defined as such:

case class Points(pts: Seq[Point])
case class Point(date: LocalDate, value: Double)

When I try to make the function call:

fromString[Points]

I get an error stating:

expected field or array
Near: \",\"value\":2.0}]}"

So normally this would imply that the JSON string is malformatted, but I confirmed that it is valid JSON. (see input string below)

"{\"pts\":[{\"date\":\"12-31-1969\",\"value\":1.0},{\"date\":\"01-31-1970\",\"value\":2.0}]}"

I have tried implementing a CustomSerializer and put it in scope of the implicit formats, but still no luck.

What am I missing?

  • 1
    Are you sure the beginning and end quotes aren't being picked up as part of the JSON? "Expected field or array" means that its not picking up "pts": [...] and instead is just seeing a string. – Charles Apr 24 '17 at 00:58
  • 1
    You have a problem escaping the quotes. It is detecting `\"` instead of just `"`. Where do you get the json from? – nmat Apr 24 '17 at 03:38
  • Thank you, both for the suggestions. The problem ended up being as you described, by having the additional " around the entire string it did not get formatted correctly for deserialization. The JSON was created incorrectly because my CustomSerializer for it was just wrong. I deleted the CustomSerializer since this class only contains standard Scala-defined & serializable objects and it worked as expected. – Jason Mathnov Apr 24 '17 at 22:31

0 Answers0