Testing Lift-4 with json4s

20 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Jan 6, 2026, 7:30:31 PM (5 days ago) Jan 6
to lif...@googlegroups.com

Hi all.

 

We're testing the lates Lift-4.0-branch, with Scala-2.13, and some changes in json4s causes us trouble.

 

We've persisted serialized values, which we need to load from DB and deserialize. These values can be everything from case class-es to primitives.

 

Take this example:

 

@Test
def testParseBoolean(): Unit = {
implicit val formats = DefaultFormats.lossless
val jValue = Extraction.decompose(true)
val jsonString = JsonMethods.compact(JsonMethods.render(jValue))
println(jsonString)
val parsedValue = JsonParser.parse(jsonString)
println(parsedValue)
}

 

The serialized value is true, but trying to deserialize the value true (parse("true")) results in:

 

org.json4s.ParserUtil$ParseException: expected field or array
Near: true

 

It's quite inconvenient that it doesn't manage to deserialize the output of the serializer to the same value.

 

Anyone knows a way to fix this?

 

--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963

Andreas Joseph Krogh

unread,
Jan 6, 2026, 7:44:28 PM (5 days ago) Jan 6
to lif...@googlegroups.com

Seems json4s' has JsonParser.newValue defined as:

def newValue(v: JValue): Unit = {
vals.peekAny match {
case (name: String, _) =>
vals.pop(classOf[JField])
val obj = vals.peek(classOf[JObject])
vals.replace(JObject((name, v) :: obj.obj))
case a: JArray => vals.replace(JArray(v :: a.arr))
case _ => p.fail("expected field or array")
}
}

 

While lift-json has:

def newValue(v: JValue) {
if (!vals.isEmpty)
vals.peekAny match {
case JField(name, value) =>
vals.pop(classOf[JField])
val obj = vals.peek(classOf[IntermediateJObject])
obj.fields += (JField(name,v))
case a: IntermediateJArray => a.bits += v
case other => p.fail("expected field or array but got " + other)
} else {
vals.push(v)
root = Some(v)
}
}

 

So, for some reason the json4s-team thought it would be fine to just skip “raw fields”….

 

Anyone familiar with this?

-- 
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/liftweb/VisenaEmail.0.94bf89a897e1ce64.19b95d670c3%40origo-test01.app.internal.visena.net.
 

Matt Farmer

unread,
Jan 6, 2026, 7:58:34 PM (5 days ago) Jan 6
to lif...@googlegroups.com
I suspect this is because json4s forked from lift-json a long time ago. Lucky for us we know someone who is a committer for json4s too. :) (me)

This is on my radar. Let me do some research and update here after. 




-------- Original Message --------

Andreas Joseph Krogh

unread,
Jan 6, 2026, 8:05:57 PM (5 days ago) Jan 6
to 'Matt Farmer' via Lift, lif...@googlegroups.com

Andreas Joseph Krogh

unread,
Jan 10, 2026, 7:39:58 AM (yesterday) Jan 10
to 'Matt Farmer' via Lift, lif...@googlegroups.com

Attached patch implements this.

 

Any chance of getting it merged upstream?

Fixed_JsonParser_to_support_fields.patch

Matt Farmer

unread,
Jan 10, 2026, 10:18:32 AM (22 hours ago) Jan 10
to lif...@googlegroups.com
You beat me to it. I've been in crisis mode all week. 🙃

Let me have a look.

Matt Farmer

unread,
Jan 10, 2026, 10:50:46 AM (22 hours ago) Jan 10
to lif...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages