Add libs-scala/struct-json (#15090)

changelog_begin
changelog_end
This commit is contained in:
Simon Maxen 2022-09-29 16:22:01 +01:00 committed by GitHub
parent 40e994bd46
commit 0654f9978c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 6 deletions

View File

@ -79,6 +79,7 @@ hj_scalacopts = lf_scalacopts + [
"//libs-scala/ports",
"//libs-scala/resources",
"//libs-scala/scala-utils",
"//libs-scala/struct-json",
"@maven//:io_dropwizard_metrics_metrics_core",
],
)

View File

@ -16,6 +16,7 @@ import scalaz.{-\/, NonEmptyList, \/-}
import spray.json._
import spray.json.derived.Discriminator
import scalaz.syntax.tag._
import com.daml.struct.json.StructJsonFormat
object JsonProtocol extends JsonProtocolLow {

View File

@ -69,6 +69,7 @@ compile_deps = [
"//libs-scala/scala-utils",
"//libs-scala/timer-utils",
"//libs-scala/nameof",
"//libs-scala/struct-json",
"@maven//:com_google_guava_guava",
"@maven//:com_zaxxer_HikariCP",
"@maven//:io_dropwizard_metrics_metrics_core",
@ -97,7 +98,6 @@ scala_compile_deps = [
"@maven//:org_playframework_anorm_anorm_tokenizer",
"@maven//:org_scalaz_scalaz_core",
"@maven//:io_spray_spray_json",
"@maven//:com_thesamet_scalapb_scalapb_json4s",
]
runtime_deps = [

View File

@ -11,9 +11,9 @@ import com.daml.lf.data.Time.Timestamp
import com.daml.platform.apiserver.meteringreport.MeteringReport._
import com.google.protobuf.struct.Struct
import com.google.protobuf.timestamp.{Timestamp => ProtoTimestamp}
import scalapb.json4s.JsonFormat
import spray.json.enrichAny
import HmacSha256.Key
import com.daml.struct.json.StructJsonFormat
class MeteringReportGenerator(participantId: Ref.ParticipantId, key: Key) {
@ -57,7 +57,7 @@ class MeteringReportGenerator(participantId: Ref.ParticipantId, key: Key) {
)
JcsSigner.sign(report, key).map { signedReport =>
JsonFormat.parser.fromJsonString[Struct](signedReport.toJson.compactPrint)
StructJsonFormat.read(signedReport.toJson)
}
}

View File

@ -0,0 +1,34 @@
# Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load(
"//bazel_tools:scala.bzl",
"da_scala_library",
"da_scala_test_suite",
)
da_scala_library(
name = "struct-json",
srcs = glob(["src/main/scala/**/*.scala"]),
scala_deps = [
"@maven//:com_thesamet_scalapb_lenses",
"@maven//:com_thesamet_scalapb_scalapb_runtime",
"@maven//:io_spray_spray_json",
],
tags = ["maven_coordinates=com.daml:struct-json:__VERSION__"],
visibility = ["//visibility:public"],
deps = [],
)
da_scala_test_suite(
name = "struct-json-test",
srcs = glob(["src/test/scala/**/*.scala"]),
scala_deps = [
"@maven//:com_thesamet_scalapb_lenses",
"@maven//:com_thesamet_scalapb_scalapb_runtime",
"@maven//:io_spray_spray_json",
],
deps = [
":struct-json",
],
)

View File

@ -1,7 +1,7 @@
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml.http.json
package com.daml.struct.json
import com.google.protobuf.struct.Struct
import spray.json.{
@ -15,7 +15,7 @@ import spray.json.{
RootJsonFormat,
}
private[json] object StructJsonFormat extends RootJsonFormat[Struct] {
object StructJsonFormat extends RootJsonFormat[Struct] {
import com.google.protobuf.struct
import com.google.protobuf.struct.Value.Kind

View File

@ -1,7 +1,7 @@
// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package com.daml.http.json
package com.daml.struct.json
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

View File

@ -265,6 +265,8 @@
type: jar-scala
- target: //libs-scala/nameof:nameof
type: jar-scala
- target: //libs-scala/struct-json:struct-json
type: jar-scala
- target: //ledger/error:error
type: jar-scala
- target: //ledger/error:error-test-lib