PlutusData annotations
This document provides an overview of the Plutus Data Annotations, which can be used to automatically generate serialization and deserialization code for custom POJO classes that can be used as Datum and Redeemer in Plutus scripts.
Code generation is performed by an annotation processor during compile time. Add com.bloxbean.cardano:cardano-client-annotation-processor to your build as an annotationProcessor dependency.
Annotations
Section titled “Annotations”- @Constr
- @PlutusIgnore
@Constr
Section titled “@Constr”This is a class-level annotation used to represent ConstrPlutusData. It takes an optional argument alternative.
@Constrpublic class Person { private String name; private String publicKey; private int age;
//Getters and Setters}The annotation processor generates a Converter class for the annotated class with the necessary serialization and deserialization methods.
Person person = new Person();person.setName("Alice");person.setPublicKey("6dcf4915b05a1358d86e87d352f2fa7392fa6c092b337af705b577822d06d17e");person.setAge(25);
//Generated Person Converter classPersonConverter converter = new PersonConverter();
//Convert to Plutus dataConstrPlutusData plutusData = converter.toPlutusData(person);
//Convert back to PersonPerson deserPerson = converter.deserialize(converter.serializeToHex(person));@PlutusIgnore
Section titled “@PlutusIgnore”This is a field-level annotation used to exclude a field from serialization and deserialization.