From d2116a8227f21fac2c2b5a61bb1bb38fb48fa219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Leuth=C3=A4user?= <1417198+max-leuthaeuser@users.noreply.github.com> Date: Mon, 28 Sep 2026 11:37:29 +0200 Subject: [PATCH 1/2] Replace json4s with com.lihaoyi.upickle For: https://harness.atlassian.net/browse/QT-1539 --- MODULE.bazel | 2 +- maven_install.json | 128 ++----------------- project/Versions.scala | 2 +- schema2json/BUILD | 3 +- schema2json/build.sbt | 2 +- schema2json/src/main/scala/Schema2Json.scala | 71 +++++----- 6 files changed, 51 insertions(+), 157 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 1616ba6c0..dfc68a5a7 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -44,7 +44,7 @@ maven.install( "io.joern:flatgraph-odb-convert_3:0.1.35", "net.sf.trove4j:core:3.1.0", "com.google.protobuf:protobuf-java:4.34.1", - "org.json4s:json4s-native_3:4.0.3", + "com.lihaoyi:ujson_3:4.4.3", "com.lihaoyi:os-lib_3:0.11.4", ], excluded_artifacts = [ diff --git a/maven_install.json b/maven_install.json index 77ab3e18d..57c71f62b 100644 --- a/maven_install.json +++ b/maven_install.json @@ -8,12 +8,12 @@ "com.google.j2objc:j2objc-annotations": 2003271689, "com.google.protobuf:protobuf-java": 1237026331, "com.lihaoyi:os-lib_3": 899915638, + "com.lihaoyi:ujson_3": 1182647324, "io.joern:flatgraph-core_3": 1060140408, "io.joern:flatgraph-domain-classes-generator_3": -1894114436, "io.joern:flatgraph-help_3": -138228966, "io.joern:flatgraph-odb-convert_3": 1959782918, "net.sf.trove4j:core": 1808260229, - "org.json4s:json4s-native_3": 1421532977, "org.scala-lang:scala-library": 1230160761, "org.scala-lang:scala3-library_3": 1771369610, "org.slf4j:slf4j-api": -197708565, @@ -45,23 +45,21 @@ "com.lihaoyi:geny_3:jar:sources": 1575781288, "com.lihaoyi:os-lib_3": 695712032, "com.lihaoyi:os-lib_3:jar:sources": 1732147675, - "com.lihaoyi:ujson_3": 126745168, - "com.lihaoyi:ujson_3:jar:sources": 1676340764, - "com.lihaoyi:upickle-core_3": 911572118, - "com.lihaoyi:upickle-core_3:jar:sources": 1793823939, - "com.thoughtworks.paranamer:paranamer": 216030769, - "com.thoughtworks.paranamer:paranamer:jar:sources": 1185138559, + "com.lihaoyi:ujson_3": -675221214, + "com.lihaoyi:ujson_3:jar:sources": 1401892679, + "com.lihaoyi:upickle-core_3": -1369261776, + "com.lihaoyi:upickle-core_3:jar:sources": 1761591552, "com.typesafe:config": 1422037420, "com.typesafe:config:jar:sources": 1794326800, "io.get-coursier:interface": 1635041630, "io.get-coursier:interface:jar:sources": -37171318, - "io.joern:flatgraph-core_3": 839026010, + "io.joern:flatgraph-core_3": 1182992137, "io.joern:flatgraph-core_3:jar:sources": 575284637, "io.joern:flatgraph-domain-classes-generator_3": 170340065, "io.joern:flatgraph-domain-classes-generator_3:jar:sources": -123490520, - "io.joern:flatgraph-help_3": -1132428533, + "io.joern:flatgraph-help_3": 1193217379, "io.joern:flatgraph-help_3:jar:sources": -1476209185, - "io.joern:flatgraph-odb-convert_3": -1972259056, + "io.joern:flatgraph-odb-convert_3": -1299461830, "io.joern:flatgraph-odb-convert_3:jar:sources": 1706697962, "io.shiftleft:overflowdb-core_3": -1655377345, "io.shiftleft:overflowdb-core_3:jar:sources": 422126785, @@ -77,16 +75,6 @@ "org.checkerframework:checker-qual:jar:sources": -1750922234, "org.javassist:javassist": -448825381, "org.javassist:javassist:jar:sources": 1531561359, - "org.json4s:json4s-ast_3": 878798110, - "org.json4s:json4s-ast_3:jar:sources": 140325100, - "org.json4s:json4s-core_3": -1327401949, - "org.json4s:json4s-core_3:jar:sources": -2043024428, - "org.json4s:json4s-native-core_3": -1463802907, - "org.json4s:json4s-native-core_3:jar:sources": -1913200314, - "org.json4s:json4s-native_3": -1745325382, - "org.json4s:json4s-native_3:jar:sources": 650512086, - "org.json4s:json4s-scalap_3": 1632132590, - "org.json4s:json4s-scalap_3:jar:sources": -763259858, "org.msgpack:msgpack-core": -1705007667, "org.msgpack:msgpack-core:jar:sources": -1562951139, "org.scalameta:scalafmt-dynamic_2.13": -518206696, @@ -194,24 +182,17 @@ }, "com.lihaoyi:ujson_3": { "shasums": { - "jar": "dd4109dc66963a3552154f59f20858e2907c13bc1a9410ae46573cdfa94e7517", - "sources": "082f8d8759a6f6db5bbed0bd13e274c404000eabb4777ff5e14a7232964d78d8" + "jar": "2fd8083aabc7fb4252c299909b19b2881326a03502eba8859d39d4b2ceb7a8b2", + "sources": "e64a5a38ab13502eb021c9fc1c8740fa825dbb11c717268fc9b308ee099ce3ae" }, - "version": "4.4.1" + "version": "4.4.3" }, "com.lihaoyi:upickle-core_3": { "shasums": { - "jar": "4b7566695c789c9a031167a296c67f08b06107124edfbb58e6e187caaa2dc592", - "sources": "ae95168d863b4df5d6f6e2c64caf02fb1da99a50b08d6d2f51b3c4ed10080a76" + "jar": "9b9be4b677ab6fbc6b82fe5486908a39664f51e9344d1903ada1c6766d251ce2", + "sources": "04a4d1a6df374a5d03f1a0ac7048dcfd60be5c4032c42355032117c375b7f647" }, - "version": "4.4.1" - }, - "com.thoughtworks.paranamer:paranamer": { - "shasums": { - "jar": "688cb118a6021d819138e855208c956031688be4b47a24bb615becc63acedf07", - "sources": "8a4bfc21755c36ccdd70f96d7ab891d842d5aebd6afa1b74e0efc6441e3df39c" - }, - "version": "2.8" + "version": "4.4.3" }, "com.typesafe:config": { "shasums": { @@ -304,41 +285,6 @@ }, "version": "3.22.0-GA" }, - "org.json4s:json4s-ast_3": { - "shasums": { - "jar": "9abf57acf0912ea87ee25950c2e717b1953c9fbd50e512005d4782ba7a014ec5", - "sources": "9a941cc22a939cadcd78fa50378bbb6f3ab09421a61af882ee8aa82257b5db4d" - }, - "version": "4.0.3" - }, - "org.json4s:json4s-core_3": { - "shasums": { - "jar": "02b5324658e08bc837a58800ee5863fb890df21b68db6c84391fa9b6d2558d1e", - "sources": "dd7784db655e6b5d41fffa9afe4bf8901a74a18785771fb404afa6109a8dd616" - }, - "version": "4.0.3" - }, - "org.json4s:json4s-native-core_3": { - "shasums": { - "jar": "e68cfc8f0c0c6a53778e6ab660d45264a8e3dc63d63c42aa9a612697583f92d9", - "sources": "80244e1308ce21e132b747be0d01ff26566a4d5082fc8ca913d86f5f3fd8d389" - }, - "version": "4.0.3" - }, - "org.json4s:json4s-native_3": { - "shasums": { - "jar": "678cbb3ee67453c7043c3784beb869bbfd51fcc66d425a4434ff100d52263dcb", - "sources": "7fc51eb72ce0b9af6bd07d14fffcb5f31ee1e5be2d7b6e6f18fc69515c503e6f" - }, - "version": "4.0.3" - }, - "org.json4s:json4s-scalap_3": { - "shasums": { - "jar": "9177935bb5f908fa5bc9a195391bffe6e822734ca711de579275bfd1922baee6", - "sources": "7abf8faab46fcaafd124dc3f4eadc4f31482dad1ff99758deb1752824ff45123" - }, - "version": "4.0.3" - }, "org.msgpack:msgpack-core": { "shasums": { "jar": "183abb2b7c604a8b13d5f76af487ccddd003b6f0404aef52021dcb20a4358524", @@ -427,18 +373,6 @@ "org.apache.commons:commons-text": [ "org.apache.commons:commons-lang3" ], - "org.json4s:json4s-core_3": [ - "com.thoughtworks.paranamer:paranamer", - "org.json4s:json4s-ast_3", - "org.json4s:json4s-scalap_3" - ], - "org.json4s:json4s-native-core_3": [ - "org.json4s:json4s-ast_3" - ], - "org.json4s:json4s-native_3": [ - "org.json4s:json4s-core_3", - "org.json4s:json4s-native-core_3" - ], "org.scalameta:scalafmt-dynamic_2.13": [ "com.typesafe:config", "io.get-coursier:interface", @@ -533,9 +467,6 @@ "upickle.core", "upickle.core.compat" ], - "com.thoughtworks.paranamer:paranamer": [ - "com.thoughtworks.paranamer" - ], "com.typesafe:config": [ "com.typesafe.config", "com.typesafe.config.impl", @@ -799,25 +730,6 @@ "javassist.util", "javassist.util.proxy" ], - "org.json4s:json4s-ast_3": [ - "org.json4s", - "org.json4s.prefs" - ], - "org.json4s:json4s-core_3": [ - "org.json4s", - "org.json4s.prefs", - "org.json4s.reflect" - ], - "org.json4s:json4s-native-core_3": [ - "org.json4s.native" - ], - "org.json4s:json4s-native_3": [ - "org.json4s.native" - ], - "org.json4s:json4s-scalap_3": [ - "org.json4s.scalap", - "org.json4s.scalap.scalasig" - ], "org.msgpack:msgpack-core": [ "org.msgpack.core", "org.msgpack.core.annotations", @@ -875,8 +787,6 @@ "com.lihaoyi:ujson_3:jar:sources", "com.lihaoyi:upickle-core_3", "com.lihaoyi:upickle-core_3:jar:sources", - "com.thoughtworks.paranamer:paranamer", - "com.thoughtworks.paranamer:paranamer:jar:sources", "com.typesafe:config", "com.typesafe:config:jar:sources", "io.get-coursier:interface", @@ -903,16 +813,6 @@ "org.checkerframework:checker-qual:jar:sources", "org.javassist:javassist", "org.javassist:javassist:jar:sources", - "org.json4s:json4s-ast_3", - "org.json4s:json4s-ast_3:jar:sources", - "org.json4s:json4s-core_3", - "org.json4s:json4s-core_3:jar:sources", - "org.json4s:json4s-native-core_3", - "org.json4s:json4s-native-core_3:jar:sources", - "org.json4s:json4s-native_3", - "org.json4s:json4s-native_3:jar:sources", - "org.json4s:json4s-scalap_3", - "org.json4s:json4s-scalap_3:jar:sources", "org.msgpack:msgpack-core", "org.msgpack:msgpack-core:jar:sources", "org.scalameta:scalafmt-dynamic_2.13", diff --git a/project/Versions.scala b/project/Versions.scala index 9ee9bce58..53d9f2aff 100644 --- a/project/Versions.scala +++ b/project/Versions.scala @@ -2,7 +2,7 @@ object Versions { val flatgraph = parseVersion("flatgraphVersion") val scalatest = "3.2.10" - val json4s = "4.0.3" + val ujson = "4.4.3" private def parseVersion(key: String): String = { val versionRegexp = s""".*val $key[ ]+=[ ]?"(.*?)"""".r diff --git a/schema2json/BUILD b/schema2json/BUILD index 6502c18ee..914443022 100644 --- a/schema2json/BUILD +++ b/schema2json/BUILD @@ -12,7 +12,6 @@ scala_binary( deps = [ "//schema", "@maven//:com_lihaoyi_os_lib_3", - "@maven//:org_json4s_json4s_ast_3", - "@maven//:org_json4s_json4s_native_3", + "@maven//:com_lihaoyi_ujson_3", ], ) diff --git a/schema2json/build.sbt b/schema2json/build.sbt index 01b87a0cb..7e436d9f6 100644 --- a/schema2json/build.sbt +++ b/schema2json/build.sbt @@ -3,7 +3,7 @@ name := "schema2json" dependsOn(Projects.schema) libraryDependencies ++= Seq( - "org.json4s" %% "json4s-native" % Versions.json4s, + "com.lihaoyi" %% "ujson" % Versions.ujson, "org.scalatest" %% "scalatest" % Versions.scalatest % Test ) diff --git a/schema2json/src/main/scala/Schema2Json.scala b/schema2json/src/main/scala/Schema2Json.scala index 367816902..cf542cea5 100644 --- a/schema2json/src/main/scala/Schema2Json.scala +++ b/schema2json/src/main/scala/Schema2Json.scala @@ -1,8 +1,4 @@ import io.shiftleft.codepropertygraph.schema.CpgSchema -import org.json4s.JsonDSL._ -import org.json4s.native.JsonMethods._ -import org.json4s.native.Serialization -import org.json4s.{Formats, NoTypeHints} import flatgraph.schema.Property.Cardinality import flatgraph.schema.{AbstractNodeType, NodeBaseType, NodeType, Property, SchemaInfo} @@ -10,16 +6,17 @@ object Schema2Json { val schema = CpgSchema.instance - implicit val formats: AnyRef & Formats = - Serialization.formats(NoTypeHints) - def main(args: Array[String]): Unit = { - val json = - ("schemas" -> schemaSummary) ~ ("nodes" -> nodeTypesAsJson) ~ ("edges" -> edgeTypesAsJson) ~ ("properties" -> propertiesAsJson) + val json = ujson.Obj( + "schemas" -> schemaSummary, + "nodes" -> nodeTypesAsJson, + "edges" -> edgeTypesAsJson, + "properties" -> propertiesAsJson + ) val outFileName = "/tmp/schema.json" - os.write(os.Path(outFileName), compact(render(json))) - // Files.writeString(Paths.get(outFileName), compact(render(json))) + os.write(os.Path(outFileName), ujson.write(json)) + // Files.writeString(Paths.get(outFileName), ujson.write(json)) println(s"Schema written to: $outFileName") } @@ -51,9 +48,7 @@ object Schema2Json { val description = info.getDeclaringClass.getDeclaredMethod("description").invoke(null).asInstanceOf[String] val providedByFrontend = info.getDeclaringClass.getDeclaredMethod("providedByFrontend").invoke(null).asInstanceOf[Boolean] - ("name" -> name) ~ - ("description" -> description) ~ - ("providedByFrontend" -> providedByFrontend) + ujson.Obj("name" -> name, "description" -> description, "providedByFrontend" -> providedByFrontend) } } @@ -74,29 +69,31 @@ object Schema2Json { } .toMap .toList - .map(x => (("baseType" -> x._2), ("name" -> x._1))) - val inheritedPropertyNames = inheritedProperties.map(_._2._2) + val inheritedPropertyNames = inheritedProperties.map(_._1) val nonInheritedProperties = allPropertyNames.filterNot(x => inheritedPropertyNames.contains(x)) val containedNodes = nodeType match { case nt: NodeType if !isSchemaHidden(nt.schemaInfo) => nt.containedNodes.map { n => - Map("name" -> n.localName, "type" -> n.nodeType.name, "cardinality" -> name(n.cardinality)) + ujson.Obj("name" -> n.localName, "type" -> n.nodeType.name, "cardinality" -> name(n.cardinality)) } case _ => List() } - val json = ("name" -> nodeType.name) ~ - ("comment" -> nodeType.comment) ~ - ("extends" -> baseTypeNames) ~ - ("allProperties" -> allPropertyNames) ~ - ("cardinalities" -> cardinalities) ~ - ("inheritedProperties" -> inheritedProperties.map(x => x._1 ~ x._2)) ~ - ("properties" -> nonInheritedProperties) ~ - ("schema" -> schName) ~ - ("schemaIndex" -> schemaIndex(nodeType)) ~ - ("isAbstract" -> nodeType.isInstanceOf[NodeBaseType]) ~ - ("containedNodes" -> containedNodes) + // n.b. `comment` is an Option; absent comments are omitted from the json (rather than rendered as `null`) + val json = ujson.Obj("name" -> nodeType.name) + nodeType.comment.foreach(comment => json("comment") = comment) + json("extends") = baseTypeNames + json("allProperties") = allPropertyNames + json("cardinalities") = cardinalities + json("inheritedProperties") = inheritedProperties.map { case (propertyName, baseTypeName) => + ujson.Obj("baseType" -> baseTypeName, "name" -> propertyName) + } + json("properties") = nonInheritedProperties + json("schema") = schName + json("schemaIndex") = schemaIndex(nodeType) + json("isAbstract") = nodeType.isInstanceOf[NodeBaseType] + json("containedNodes") = containedNodes Some(json) } } @@ -107,11 +104,10 @@ object Schema2Json { .filterNot(x => isSchemaHidden(x.schemaInfo)) .flatMap { edge => val schName = schemaName(edge.schemaInfo) - Some( - ("name" -> edge.name) ~ - ("comment" -> edge.comment) ~ - ("schema" -> schName) - ) + val json = ujson.Obj("name" -> edge.name) + edge.comment.foreach(comment => json("comment") = comment) + json("schema") = schName + Some(json) } } @@ -121,11 +117,10 @@ object Schema2Json { .filterNot(x => isSchemaHidden(x.schemaInfo)) .flatMap { prop => val schName = schemaName(prop.schemaInfo) - Some( - ("name" -> prop.name) ~ - ("comment" -> prop.comment) ~ - ("schema" -> schName) - ) + val json = ujson.Obj("name" -> prop.name) + prop.comment.foreach(comment => json("comment") = comment) + json("schema") = schName + Some(json) } } From b67c35b8bfe2d5afc13ee7fb5679464d187fb68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20Leuth=C3=A4user?= <1417198+max-leuthaeuser@users.noreply.github.com> Date: Mon, 28 Sep 2026 12:04:44 +0200 Subject: [PATCH 2/2] remove comment --- schema2json/src/main/scala/Schema2Json.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/schema2json/src/main/scala/Schema2Json.scala b/schema2json/src/main/scala/Schema2Json.scala index cf542cea5..97f4293eb 100644 --- a/schema2json/src/main/scala/Schema2Json.scala +++ b/schema2json/src/main/scala/Schema2Json.scala @@ -80,7 +80,6 @@ object Schema2Json { } case _ => List() } - // n.b. `comment` is an Option; absent comments are omitted from the json (rather than rendered as `null`) val json = ujson.Obj("name" -> nodeType.name) nodeType.comment.foreach(comment => json("comment") = comment) json("extends") = baseTypeNames