com.weavechain.core.error.Pending Maven / Gradle / Ivy
package com.weavechain.core.error;
import com.google.gson.*;
import com.weavechain.core.encoding.Utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.lang.reflect.Type;
@Getter
@AllArgsConstructor
public class Pending implements OperationResult {
OperationScope target;
@Getter
Object data;
@Override
public String getStringData() {
return data instanceof String ? (String)data : Utils.getGson().toJson(data);
}
@Override
public boolean isError() {
return false;
}
@Override
public String getMessage() {
return OperationResultSerializer.PENDING;
}
@Override
public Object getMetadata() {
return null;
}
@Override
public String getStringMetadata() {
return null;
}
@Override
public String getIds() {
return null;
}
@Override
public String getHashes() {
return null;
}
@Override
public OperationResult toAuditRecord() {
return this;
}
public static class Serializer implements JsonSerializer {
public JsonElement serialize(Pending data, Type typeOfSrc, JsonSerializationContext context) {
JsonObject element = new JsonObject();
element.add("res", new JsonPrimitive(OperationResultSerializer.PENDING));
if (data.getTarget() != null) {
element.add("target", Utils.getGson().toJsonTree(data.getTarget()));
}
if (data.getData() != null) {
element.add("data", new JsonPrimitive(data.getStringData()));
}
return element;
}
}
}