mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-10 10:46:11 +03:00
Java Codegen: classes get keyToJson via inheritance rather than re-generating for each class (#18385)
This commit is contained in:
parent
094c392ae7
commit
2ff3f7c378
@ -132,26 +132,11 @@ private[inner] object ToJsonGenerator {
|
||||
.methodBuilder("keyJsonEncoder")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.returns(classOf[JsonLfEncoder])
|
||||
.addAnnotation(classOf[Override])
|
||||
.addStatement("return this.key.map($L).orElse(null)", encoderOf(keyDamlType))
|
||||
.build()
|
||||
|
||||
val toString = MethodSpec
|
||||
.methodBuilder("keyToJson")
|
||||
.addModifiers(Modifier.PUBLIC)
|
||||
.addStatement("var enc = keyJsonEncoder()")
|
||||
.addStatement("if (enc == null) return null")
|
||||
.addStatement("var w = new $T()", classOf[StringWriter])
|
||||
.beginControlFlow("try")
|
||||
.addStatement("enc.encode(new $T(w))", classOf[JsonLfWriter])
|
||||
.nextControlFlow("catch ($T e)", classOf[IOException])
|
||||
.addComment("Not expected with StringWriter")
|
||||
.addStatement("throw new $T(e)", classOf[UncheckedIOException])
|
||||
.endControlFlow()
|
||||
.addStatement("return w.toString()")
|
||||
.returns(classOf[String])
|
||||
.build()
|
||||
|
||||
Seq(encoder, toString)
|
||||
Seq(encoder)
|
||||
}
|
||||
|
||||
// When a type has type parameters (generic classes), we need to tell
|
||||
|
Loading…
Reference in New Issue
Block a user