com.casper.sdk.jackson.serializer.TransactionSchedulingSerializer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of casper-java-sdk Show documentation
Show all versions of casper-java-sdk Show documentation
SDK to streamline the 3rd party Java client integration processes. Such 3rd parties include exchanges & app developers.
The newest version!
package com.casper.sdk.jackson.serializer;
import com.casper.sdk.model.transaction.scheduling.FutureEra;
import com.casper.sdk.model.transaction.scheduling.FutureTimestamp;
import com.casper.sdk.model.transaction.scheduling.Standard;
import com.casper.sdk.model.transaction.scheduling.TransactionScheduling;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
/**
* Serializes {@link TransactionScheduling} objects.
*
* @author [email protected]
*/
public class TransactionSchedulingSerializer extends JsonSerializer {
@Override
public void serialize(final TransactionScheduling value,
final JsonGenerator gen,
final SerializerProvider serializers) throws IOException {
if (value instanceof Standard) {
gen.writeString("Standard");
} else if (value instanceof FutureTimestamp) {
gen.writeStartObject();
gen.writeStringField(FutureTimestamp.class.getSimpleName(), ((FutureTimestamp) value).getFutureTimestamp());
gen.writeEndObject();
} else if (value instanceof FutureEra) {
gen.writeStartObject();
gen.writeStringField(FutureEra.class.getSimpleName(), ((FutureEra) value).getEraId().toString());
gen.writeEndObject();
} else {
throw new IllegalArgumentException("Unknown scheduling type: " + value.getClass().getName());
}
}
}