Class Mapper

java.lang.Object
com.couchbase.client.core.json.Mapper

@Internal public class Mapper extends Object
Provides utilities for encoding and decoding JSON data.
Since:
2.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    convertValue(Object fromValue, com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef)
    Converts an object to the requested type using ObjectMapper.convertValue(Object, TypeReference).
    static <T> T
    convertValue(Object fromValue, Class<T> toValueType)
    Converts an object to the requested type using ObjectMapper.convertValue(Object, Class).
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode
    Returns a new empty ArrayNode.
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode
    Returns a new empty ObjectNode.
    static <T> T
    decodeInto(byte[] input, com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference<T> type)
    Decodes a byte array into the given type.
    static <T> T
    decodeInto(byte[] input, Class<T> clazz)
    Decodes a byte array into the given class.
    static <T> T
    decodeInto(String input, com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference<T> type)
    Decodes a String into the given type.
    static <T> T
    decodeInto(String input, Class<T> clazz)
    Decodes a String into the given class.
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode
    decodeIntoTree(byte[] input)
    Decodes a byte array into a tree of JSON nodes.
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode
    Decodes a string into a tree of JSON nodes.
    static byte[]
    Encodes the given input into a byte array, formatted non-pretty.
    static byte[]
    Encodes the given input into a byte array, formatted pretty.
    static String
    Encodes the given input into a String, formatted non-pretty.
    static String
    Encodes the given input into a String, formatted pretty.
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectMapper
     
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectReader
    Returns an ObjectReader for advanced use cases.
    static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectWriter
    Returns an ObjectWriter for advanced use cases.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • newObjectMapper

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectMapper newObjectMapper()
    • encodeAsBytes

      public static byte[] encodeAsBytes(Object input)
      Encodes the given input into a byte array, formatted non-pretty.
      Parameters:
      input - the java object as input
      Returns:
      the json encoded byte array.
    • encodeAsBytesPretty

      public static byte[] encodeAsBytesPretty(Object input)
      Encodes the given input into a byte array, formatted pretty.
      Parameters:
      input - the java object as input
      Returns:
      the json encoded byte array.
    • encodeAsString

      public static String encodeAsString(Object input)
      Encodes the given input into a String, formatted non-pretty.
      Parameters:
      input - the java object as input
      Returns:
      the json encoded String.
    • encodeAsStringPretty

      public static String encodeAsStringPretty(Object input)
      Encodes the given input into a String, formatted pretty.
      Parameters:
      input - the java object as input
      Returns:
      the json encoded String.
    • decodeInto

      public static <T> T decodeInto(byte[] input, Class<T> clazz)
      Decodes a byte array into the given class.
      Type Parameters:
      T - generic type used for inference.
      Parameters:
      input - the input byte array.
      clazz - the clazz which should be decoded into.
      Returns:
      the created instance.
    • decodeInto

      public static <T> T decodeInto(String input, Class<T> clazz)
      Decodes a String into the given class.
      Type Parameters:
      T - generic type used for inference.
      Parameters:
      input - the input byte array.
      clazz - the clazz which should be decoded into.
      Returns:
      the created instance.
    • decodeInto

      public static <T> T decodeInto(byte[] input, com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference<T> type)
      Decodes a byte array into the given type.
      Type Parameters:
      T - generic type used for inference.
      Parameters:
      input - the input byte array.
      type - the type which should be decoded into.
      Returns:
      the created instance.
    • decodeInto

      public static <T> T decodeInto(String input, com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference<T> type)
      Decodes a String into the given type.
      Type Parameters:
      T - generic type used for inference.
      Parameters:
      input - the input byte array.
      type - the type which should be decoded into.
      Returns:
      the created instance.
    • decodeIntoTree

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode decodeIntoTree(byte[] input)
      Decodes a byte array into a tree of JSON nodes.
      Parameters:
      input - the input byte array.
      Returns:
      the created node.
    • decodeIntoTree

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.JsonNode decodeIntoTree(String input)
      Decodes a string into a tree of JSON nodes.
      Parameters:
      input - the input byte array.
      Returns:
      the created node.
    • convertValue

      public static <T> T convertValue(Object fromValue, Class<T> toValueType)
      Converts an object to the requested type using ObjectMapper.convertValue(Object, Class).
    • convertValue

      public static <T> T convertValue(Object fromValue, com.couchbase.client.core.deps.com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef)
      Converts an object to the requested type using ObjectMapper.convertValue(Object, TypeReference).
    • reader

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectReader reader()
      Returns an ObjectReader for advanced use cases.
    • writer

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.ObjectWriter writer()
      Returns an ObjectWriter for advanced use cases.
    • createObjectNode

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ObjectNode createObjectNode()
      Returns a new empty ObjectNode.
    • createArrayNode

      public static com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode createArrayNode()
      Returns a new empty ArrayNode.