All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.weavechain.core.error.Pending Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy