Can I get schema from com.daml.ledger.javaapi.data.CreatedEvent;
- FrankieOP
In Java implementation, is there a way to retrieve the data schema from CreatedEvent? e.g. template field name, data type etc? Is it in the Map returned by getInterfaceViews()? Thanks.
- cocreature
You can’t get the full schema out of a CreatedEvent. If you set
verbose = trueon your transaction stream you will at least get field names though.CreatedEventhere is just a small wrapper around the underlying protobufCreatedEventand doesn’t expose additional information.getInterfaceViewsis about Daml interfaces not about exposing schema information. - cocreature
The java codegen types give you some metadata like the available choices on the template. Not sure if that’s what you’re looking for.
- Frankie
Thanks for the prompt reply @cocreature. I was looking for a way to write the events into a JSON objects and feed them to downstream systems. Being able to get schema would be a advantage since the layer doesn’t need to be updated when a new template is uploaded.
- cocreature
The way the JSON API handles this is by polling the package endpoint and based on that building up its own schema definition based on the package contents. When it sees a
CreatedEventit can then do a lookup based on the template id to find the schema. - Stephen 1
Frankie:I was looking for a way to write the events into a JSON objects and feed them to downstream systems.
For what it’s worth, in Daml 2.6.0 we will provide a
codegen-json-javalibrary, written in Scala but should be usable from Java, which can encode the payload fromCreatedEventinto the standard encoding used by the JSON API.Your exact expression may vary, but might be something like this:
var codec = JsonCodec.apply(true, true); // encode all nums as strings var jsonStructure = codec.toJsValue(createdEvent.getArguments()); // toJsValue can also encode codegen-decoded contract payloads and views var encodedString = jsonStructure.compactPrint(); // or prettyPrint or something else to get a string // or you can further embed jsonStructure in a larger JSON...structureThe source code is straightforward and Apache-licensed, and may be of use to you in advance of the 2.6.0 release.
- Frankie
@cocreature, I’m trying to learn and use the custom-view lib at the moment. (ex-custom-views-spring-boot/ProjectionRunner.java at 62829968b8e2a0ea7d2f8aecfeafade6aae369e9 · digital-asset/ex-custom-views-spring-boot · GitHub) Can verbose = true be set on custom-view lib?
- cocreature
Looks like this is currently not exposed, you would need to set
verbose = truein theGetTransactionsRequesthere. - Frankie
May I request this feature to be included in custom-view?