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

com.hedera.hapi.node.state.token.codec.AccountPendingAirdropJsonCodec Maven / Gradle / Ivy

package com.hedera.hapi.node.state.token.codec;

import com.hedera.pbj.runtime.*;
import com.hedera.pbj.runtime.io.*;
import com.hedera.pbj.runtime.io.buffer.*;
import java.io.IOException;
import java.nio.*;
import java.nio.charset.*;
import java.util.*;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

import com.hedera.hapi.node.state.token.AccountPendingAirdrop;

import com.hedera.hapi.node.base.*;
import com.hedera.hapi.node.base.codec.*;
import com.hedera.hapi.node.state.token.*;
import com.hedera.hapi.node.state.token.schema.*;

import com.hedera.pbj.runtime.jsonparser.*;
import static com.hedera.hapi.node.state.token.schema.AccountPendingAirdropSchema.*;
import static com.hedera.pbj.runtime.JsonTools.*;

/**
 * JSON Codec for AccountPendingAirdrop model object. Generated based on protobuf schema.
 */
public final class AccountPendingAirdropJsonCodec implements JsonCodec {
    

        /**
     * Parses a HashObject object from JSON parse tree for object JSONParser.ObjContext.
     * Throws an UnknownFieldException wrapped in a ParseException if in strict mode ONLY.
     *
     * @param root The JSON parsed object tree to parse data from
     * @return Parsed HashObject model object or null if data input was null or empty
     * @throws ParseException If parsing fails
     */
    public @NonNull AccountPendingAirdrop parse(
            @Nullable final JSONParser.ObjContext root,
            final boolean strictMode,
            final int maxDepth) throws ParseException {
        if (maxDepth < 0) {
            throw new ParseException("Reached maximum allowed depth of nested messages");
        }
        try {
            // -- TEMP STATE FIELDS --------------------------------------
                PendingAirdropValue temp_pending_airdrop_value = null;
        PendingAirdropId temp_previous_airdrop = null;
        PendingAirdropId temp_next_airdrop = null;
    
            // -- EXTRACT VALUES FROM PARSE TREE ---------------------------------------------
    
            for (JSONParser.PairContext kvPair : root.pair()) {
                switch (kvPair.STRING().getText()) {
                    case "pendingAirdropValue" /* [1] */ : temp_pending_airdrop_value = PendingAirdropValue.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "previousAirdrop" /* [2] */ : temp_previous_airdrop = PendingAirdropId.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    case "nextAirdrop" /* [3] */ : temp_next_airdrop = PendingAirdropId.JSON.parse(kvPair.value().getChild(JSONParser.ObjContext.class, 0), false, maxDepth - 1); break;
    
                    default: {
                        if (strictMode) {
                            // Since we are parsing is strict mode, this is an exceptional condition.
                            throw new UnknownFieldException(kvPair.STRING().getText());
                        }
                    }
                }
            }
    
            return new AccountPendingAirdrop(temp_pending_airdrop_value, temp_previous_airdrop, temp_next_airdrop);
        } catch (Exception ex) {
            throw new ParseException(ex);
        }
    }

        /**
     * Returns JSON string representing an item.
     *
     * @param data      The item to convert. Must not be null.
     * @param indent    The indent to use for pretty printing
     * @param inline    When true the output will start with indent end with a new line otherwise
     *                        it will just be the object "{...}"
     */
    @Override
    public String toJSON(@NonNull AccountPendingAirdrop data, String indent, boolean inline) {
        StringBuilder sb = new StringBuilder();
        // start
        sb.append(inline ? "{\n" : indent + "{\n");
        final String childIndent = indent + INDENT;
        // collect field lines
        final List fieldLines = new ArrayList<>();
            // [1] - pending_airdrop_value
        if (data.pendingAirdropValue() != null) fieldLines.add(field(childIndent, "pendingAirdropValue", com.hedera.hapi.node.base.PendingAirdropValue.JSON, data.pendingAirdropValue()));
        // [2] - previous_airdrop
        if (data.previousAirdrop() != null) fieldLines.add(field(childIndent, "previousAirdrop", com.hedera.hapi.node.base.PendingAirdropId.JSON, data.previousAirdrop()));
        // [3] - next_airdrop
        if (data.nextAirdrop() != null) fieldLines.add(field(childIndent, "nextAirdrop", com.hedera.hapi.node.base.PendingAirdropId.JSON, data.nextAirdrop()));
    
        // write field lines
        if (!fieldLines.isEmpty()){
            sb.append(childIndent);
            sb.append(String.join(",\n"+childIndent, fieldLines));
            sb.append("\n");
        }
        // end
        sb.append(indent + "}");
        return sb.toString();
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy