Pojo Serializer and Deserializer
Use PojoSerializer and PojoDeserializer to serialize and deserialize the annotated POJO (Plain Old Java Object) to and from Candid payload of type RECORD.
Serializer and Deserializer will use Candid Java annotations to get the Candid Name and Type.
A fully functional example using PojoSerializer and PojoDeserializer can be found here.
This example calls a canister using Motoko main.mo.
The canister uses 2 complex types, LoanApplication and LoanOffer.
// Loan Application
public type LoanApplication = {
id: Nat;
firstname: Text;
lastname: Text;
zipcode: Text;
ssn: Text;
amount: Float;
term: Nat16;
created: Int;
};
// Loan Offer
public type LoanOffer = {
providerid: Principal;
providername: Text;
applicationid: Nat;
apr: Float;
created: Int;
};The canister has 2 methods apply and getOffers.
To call this canister the annotated proxy Java interface LoanProxy.java and ProxyBuilder will be used.
LoanApplication and LoanOffer Java classes with the Candid annotation are defined in LoanApplication.java and LoanOffer.java.
By default, PojoSerializer and PojoDeserializer will use Java to Candid type mapping and use the Java member variable name as the name of the Candid RECORD field.
Use Candid annotations @Field to override the default type and @Name to override the default name.
To skip serialization and deserialization of certain member variables, use the @Ignore annotation.
ProxyBuilder will implicitly use PojoSerializer and PojoDeserializer to convert Candid RECORD to a Java object.
To use Raw methods or QueryBuilder and UpdateBuilder use PojoSerializer and PojoDeserializer directly in the Java code.
Last updated