Class ManBindingsExt


  • public class ManBindingsExt
    extends Object
    Extends Bindings with methods to transform the Bindings contents to JSON, YAML, CSV, and XML and to conveniently use the Bindings for JSON Web services.
    • Constructor Summary

      Constructors 
      Constructor Description
      ManBindingsExt()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static manifold.rt.api.Bindings deepCopy​(manifold.rt.api.Bindings thiz)
      Provide a deep copy of this Bindings using a DataBindings for the copy.
      static <E extends manifold.rt.api.Bindings>
      E
      deepCopy​(manifold.rt.api.Bindings thiz, Function<Integer,​E> bindingsSupplier)
      Provide a deep copy of this Bindings.
      static <E extends Map<String,​Object>>
      Object
      deepCopyValue​(Object value, Function<Integer,​E> bindingsSupplier)  
      static void listToJson​(StringBuilder target, int indent, List value)
      Utility to serialize a List composed of JSON values, where a JSON value is one of: a simple type such as a String, number, or boolean a Bindings of property names to JSON values a List composed of JSON values
      static String listToJson​(List list)
      Serializes a JSON-compatible List into a JSON formatted StringBuilder with the specified indent of spaces.
      static URL makeUrl​(manifold.rt.api.Bindings thiz, String url)
      Make a JSON-compatible URL with the arguments from this Bindings.
      static Object sendJsonRequest​(manifold.rt.api.Bindings thiz, String httpMethod, String url)
      Use HTTP GET, POST, PUT, PATCH, or DELETE to send this Bindings to a URL with a JSON response.
      static Object sendYamlRequest​(manifold.rt.api.Bindings thiz, String httpMethod, String url)
      Use HTTP GET, POST, PUT, PATCH, or DELETE to send this Bindings to a URL with a YAML response.
      static String toCsv​(manifold.rt.api.Bindings thiz)
      Serializes this Bindings instance to CSV nested in a root element named "object"
      static String toCsv​(manifold.rt.api.Bindings thiz, String name)
      Serializes this Bindings instance to CSV with in a root element with the specified name
      static void toCsv​(manifold.rt.api.Bindings thiz, String name, StringBuilder target, int indent)
      Serializes this Bindings instance into an CSV formatted StringBuilder target with the specified indent of spaces.
      static String toJson​(manifold.rt.api.Bindings thiz)
      Serializes this Bindings instance to a JSON formatted String
      static void toJson​(manifold.rt.api.Bindings thiz, StringBuilder target, int margin)
      Serializes this Bindings instance into a JSON formatted StringBuilder target with the specified indent of spaces.
      static String toXml​(manifold.rt.api.Bindings thiz)
      Serializes this Bindings instance to XML nested in a root element named "object"
      static String toXml​(manifold.rt.api.Bindings thiz, String name)
      Serializes this Bindings instance to XML with in a root element with the specified name
      static void toXml​(manifold.rt.api.Bindings thiz, String name, StringBuilder target, int indent)
      Serializes this Bindings instance into an XML formatted StringBuilder target with the specified indent of spaces.
      static String toYaml​(manifold.rt.api.Bindings thiz)
      Serializes this Bindings instance to a YAML formatted String
      static void toYaml​(manifold.rt.api.Bindings thiz, StringBuilder target)
      Serializes this Bindings instance into a YAML 1.2 formatted StringBuilder target with the specified indent of spaces.
    • Constructor Detail

      • ManBindingsExt

        public ManBindingsExt()
    • Method Detail

      • toJson

        public static String toJson​(manifold.rt.api.Bindings thiz)
        Serializes this Bindings instance to a JSON formatted String
        Returns:
        This Bindings instance serialized to a JSON formatted String
      • toYaml

        public static String toYaml​(manifold.rt.api.Bindings thiz)
        Serializes this Bindings instance to a YAML formatted String
        Returns:
        This Bindings instance serialized to a YAML formatted String
      • toJson

        public static void toJson​(manifold.rt.api.Bindings thiz,
                                  StringBuilder target,
                                  int margin)
        Serializes this Bindings instance into a JSON formatted StringBuilder target with the specified indent of spaces.
        Parameters:
        target - A StringBuilder to write the JSON in
        margin - The margin of spaces to indent the resulting block of JSON
      • toYaml

        public static void toYaml​(manifold.rt.api.Bindings thiz,
                                  StringBuilder target)
        Serializes this Bindings instance into a YAML 1.2 formatted StringBuilder target with the specified indent of spaces.
        Parameters:
        target - A StringBuilder to write the YAML in
      • listToJson

        public static void listToJson​(StringBuilder target,
                                      int indent,
                                      List value)
        Utility to serialize a List composed of JSON values, where a JSON value is one of:
        • a simple type such as a String, number, or boolean
        • a Bindings of property names to JSON values
        • a List composed of JSON values
        Parameters:
        target - A StringBuilder to write the JSON in
        indent - The margin of spaces to indent the JSON
        value - A List composed of JSON values to serialize
      • listToJson

        public static String listToJson​(List list)
        Serializes a JSON-compatible List into a JSON formatted StringBuilder with the specified indent of spaces. Same as calling listToJson(StringBuilder, int, List) with no indentation and returns a String.
      • toXml

        public static String toXml​(manifold.rt.api.Bindings thiz,
                                   String name)
        Serializes this Bindings instance to XML with in a root element with the specified name
        Parameters:
        name - The name of the root element to nest the Bindings XML
        See Also:
        toXml(Bindings, String, StringBuilder, int)
      • toXml

        public static void toXml​(manifold.rt.api.Bindings thiz,
                                 String name,
                                 StringBuilder target,
                                 int indent)
        Serializes this Bindings instance into an XML formatted StringBuilder target with the specified indent of spaces.
        Parameters:
        name - The name of the root element to nest the Bindings XML
        target - A StringBuilder to write the XML in
        indent - The margin of spaces to indent the XML
      • toCsv

        public static String toCsv​(manifold.rt.api.Bindings thiz,
                                   String name)
        Serializes this Bindings instance to CSV with in a root element with the specified name
        Parameters:
        name - The name of the root element to nest the Bindings CSV
        See Also:
        toCsv(Bindings, String, StringBuilder, int)
      • toCsv

        public static void toCsv​(manifold.rt.api.Bindings thiz,
                                 String name,
                                 StringBuilder target,
                                 int indent)
        Serializes this Bindings instance into an CSV formatted StringBuilder target with the specified indent of spaces.
        Parameters:
        name - The name of the root element to nest the Bindings CSV
        target - A StringBuilder to write the CSV in
        indent - The margin of spaces to indent the CSV
      • makeUrl

        public static URL makeUrl​(manifold.rt.api.Bindings thiz,
                                  String url)
        Make a JSON-compatible URL with the arguments from this Bindings. URL encodes the arguments in UTF-8 and appends them to the list using standard URL query delimiters.

        If an argument is a Bindings or a List, it is transformed to JSON. Otherwise, the argument is coerced to a String and URL encoded.

        Parameters:
        url - The base URL to extend with encoded arguments from this Bindings
        Returns:
        The URL with JSON-encoded arguments from this Bindings
      • sendJsonRequest

        public static Object sendJsonRequest​(manifold.rt.api.Bindings thiz,
                                             String httpMethod,
                                             String url)
        Use HTTP GET, POST, PUT, PATCH, or DELETE to send this Bindings to a URL with a JSON response.
        Parameters:
        httpMethod - HTTP method to use: "GET", "POST", "PUT", "PATCH", or "DELETE"
        url - The URL to send this Bindings to
        Returns:
        The full content of this URL's JSON response as a JSON value.
        See Also:
        ManUrlExt.sendJsonRequest(URL, String, Object)
      • sendYamlRequest

        public static Object sendYamlRequest​(manifold.rt.api.Bindings thiz,
                                             String httpMethod,
                                             String url)
        Use HTTP GET, POST, PUT, PATCH, or DELETE to send this Bindings to a URL with a YAML response.
        Parameters:
        httpMethod - HTTP method to use: "GET", "POST", "PUT", "PATCH", or "DELETE"
        url - The URL to send this Bindings to
        Returns:
        The full content of this URL's YAML response as a JSON value.
        See Also:
        ManUrlExt.sendYamlRequest(URL, String, Object)
      • deepCopy

        public static manifold.rt.api.Bindings deepCopy​(manifold.rt.api.Bindings thiz)
        Provide a deep copy of this Bindings using a DataBindings for the copy.

        Same as invoking: deepCopy(DataBindings::new)

        Returns:
        A deep copy of this Bindings
      • deepCopy

        public static <E extends manifold.rt.api.Bindings> E deepCopy​(manifold.rt.api.Bindings thiz,
                                                                      Function<Integer,​E> bindingsSupplier)
        Provide a deep copy of this Bindings. Note this method assumes the Bindings is limited to a JSON style Bindings<String, Value> where Value type is strictly:
        • a String, Number, or Boolean
        • a List of Value
        • a Bindings of String to Value
        Any deviation from this format may result in unexpected behavior.
        Parameters:
        bindingsSupplier - Creates the Bindings instance used for the copy and instances for nested Bindings.
        Returns:
        A deep copy of this Bindings