Can I get schema from;

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.

You can’t get the full schema out of a CreatedEvent. If you set verbose = true on your transaction stream you will at least get field names though. CreatedEvent here is just a small wrapper around the underlying protobuf CreatedEvent and doesn’t expose additional information.

getInterfaceViews is about Daml interfaces not about exposing schema information.

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.

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.

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 CreatedEvent it can then do a lookup based on the template id to find the schema.

For what it’s worth, in Daml 2.6.0 we will provide a codegen-json-java library, written in Scala but should be usable from Java, which can encode the payload from CreatedEvent into 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...structure

The source code is straightforward and Apache-licensed, and may be of use to you in advance of the 2.6.0 release.

1 Like

@cocreature, I’m trying to learn and use the custom-view lib at the moment. (ex-custom-views-spring-boot/ at 62829968b8e2a0ea7d2f8aecfeafade6aae369e9 · digital-asset/ex-custom-views-spring-boot · GitHub) Can verbose = true be set on custom-view lib?

Looks like this is currently not exposed, you would need to set verbose = true in the GetTransactionsRequest here.

May I request this feature to be included in custom-view?