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

graphql.scalar.GraphqlStringCoercing Maven / Gradle / Ivy

There is a newer version: 230521-nf-execution
Show newest version
package graphql.scalar;

import graphql.Internal;
import graphql.language.StringValue;
import graphql.language.Value;
import graphql.schema.Coercing;
import graphql.schema.CoercingParseLiteralException;

import static graphql.scalar.CoercingUtil.typeName;

@Internal
public class GraphqlStringCoercing implements Coercing {
    @Override
    public String serialize(Object input) {
        return input.toString();
    }

    @Override
    public String parseValue(Object input) {
        return serialize(input);
    }

    @Override
    public String parseLiteral(Object input) {
        if (!(input instanceof StringValue)) {
            throw new CoercingParseLiteralException(
                    "Expected AST type 'StringValue' but was '" + typeName(input) + "'."
            );
        }
        return ((StringValue) input).getValue();
    }

    @Override
    public Value valueToLiteral(Object input) {
        return StringValue.newStringValue(input.toString()).build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy