Class GraphQLRequestSerializer

java.lang.Object
io.github.besi97.graphql.codegen.model.graphql.GraphQLRequestSerializer

public class GraphQLRequestSerializer extends Object
Serializer of GraphQL request. Provides ability to convert GraphQLRequest object to HTTP Json body, as well as to raw query string.
  • Field Details

    • OBJECT_MAPPER

      public static final com.fasterxml.jackson.databind.ObjectMapper OBJECT_MAPPER
  • Method Details

    • toHttpJsonBody

      public static String toHttpJsonBody(GraphQLRequests graphQLRequests)
      Serializes GraphQL requests to be used as HTTP JSON body according to https://graphql.org/learn/serving-over-http specifications
      Parameters:
      graphQLRequests - GraphQL requests to serialize
      Returns:
      the serialized request
    • toHttpJsonBody

      public static String toHttpJsonBody(GraphQLRequest graphQLRequest)
      Serializes GraphQL request to be used as HTTP JSON body according to https://graphql.org/learn/serving-over-http specifications
      Parameters:
      graphQLRequest - the GraphQL request to serialize
      Returns:
      the serialized request
    • toQueryString

      public static String toQueryString(GraphQLRequest graphQLRequest)
      Serializes GraphQL request as raw query string
      Parameters:
      graphQLRequest - the GraphQL request to serialize
      Returns:
      the serialized request
    • getEntry

      public static String getEntry(Object input)
    • getEntry

      public static String getEntry(Object input, boolean useObjectMapper)
      Serialize object to a string
      Parameters:
      input - can be any object or collection/map of objects.
      useObjectMapper - if true, then use Jackson's ObjectMapper to convert from object to string, otherwise use toString
      Returns:
      serialized object
    • serializeCollection

      public static String serializeCollection(Collection<?> input, boolean useObjectMapper)
    • serializeMap

      public static String serializeMap(Map<?,?> input, boolean useObjectMapper)
    • serializeMapEntry

      public static String serializeMapEntry(Map.Entry<?,?> input, boolean useObjectMapper)
    • serializeEnum

      public static String serializeEnum(Enum<?> input)
    • escapeJsonString

      public static String escapeJsonString(String stringValue)
      Encodes the value as a JSON string according to http://json.org/ rules
      Parameters:
      stringValue - the value to encode as a JSON string
      Returns:
      the encoded string
    • objectMapperWriteValueAsString

      public static String objectMapperWriteValueAsString(Object input)