Class ManBindingsExt
- java.lang.Object
-
- manifold.json.rt.extensions.manifold.rt.api.Bindings.ManBindingsExt
-
public class ManBindingsExt extends Object
ExtendsBindingswith 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.BindingsdeepCopy(manifold.rt.api.Bindings thiz)Provide a deep copy of thisBindingsusing aDataBindingsfor the copy.static <E extends manifold.rt.api.Bindings>
EdeepCopy(manifold.rt.api.Bindings thiz, Function<Integer,E> bindingsSupplier)Provide a deep copy of thisBindings.static <E extends Map<String,Object>>
ObjectdeepCopyValue(Object value, Function<Integer,E> bindingsSupplier)static voidlistToJson(StringBuilder target, int indent, List value)static StringlistToJson(List list)Serializes a JSON-compatible List into a JSON formatted StringBuilder with the specified indent of spaces.static URLmakeUrl(manifold.rt.api.Bindings thiz, String url)Make a JSON-compatible URL with the arguments from thisBindings.static ObjectsendJsonRequest(manifold.rt.api.Bindings thiz, String httpMethod, String url)Use HTTP GET, POST, PUT, PATCH, or DELETE to send thisBindingsto a URL with a JSON response.static ObjectsendYamlRequest(manifold.rt.api.Bindings thiz, String httpMethod, String url)Use HTTP GET, POST, PUT, PATCH, or DELETE to send thisBindingsto a URL with a YAML response.static StringtoCsv(manifold.rt.api.Bindings thiz)Serializes thisBindingsinstance to CSV nested in a root element named"object"static StringtoCsv(manifold.rt.api.Bindings thiz, String name)Serializes thisBindingsinstance to CSV with in a root element with the specifiednamestatic voidtoCsv(manifold.rt.api.Bindings thiz, String name, StringBuilder target, int indent)Serializes thisBindingsinstance into an CSV formatted StringBuildertargetwith the specifiedindentof spaces.static StringtoJson(manifold.rt.api.Bindings thiz)Serializes thisBindingsinstance to a JSON formatted Stringstatic voidtoJson(manifold.rt.api.Bindings thiz, StringBuilder target, int margin)Serializes thisBindingsinstance into a JSON formatted StringBuildertargetwith the specifiedindentof spaces.static StringtoXml(manifold.rt.api.Bindings thiz)Serializes thisBindingsinstance to XML nested in a root element named"object"static StringtoXml(manifold.rt.api.Bindings thiz, String name)Serializes thisBindingsinstance to XML with in a root element with the specifiednamestatic voidtoXml(manifold.rt.api.Bindings thiz, String name, StringBuilder target, int indent)Serializes thisBindingsinstance into an XML formatted StringBuildertargetwith the specifiedindentof spaces.static StringtoYaml(manifold.rt.api.Bindings thiz)Serializes thisBindingsinstance to a YAML formatted Stringstatic voidtoYaml(manifold.rt.api.Bindings thiz, StringBuilder target)Serializes thisBindingsinstance into a YAML 1.2 formatted StringBuildertargetwith the specifiedindentof spaces.
-
-
-
Method Detail
-
toJson
public static String toJson(manifold.rt.api.Bindings thiz)
Serializes thisBindingsinstance to a JSON formatted String- Returns:
- This
Bindingsinstance serialized to a JSON formatted String
-
toYaml
public static String toYaml(manifold.rt.api.Bindings thiz)
Serializes thisBindingsinstance to a YAML formatted String- Returns:
- This
Bindingsinstance serialized to a YAML formatted String
-
toJson
public static void toJson(manifold.rt.api.Bindings thiz, StringBuilder target, int margin)Serializes thisBindingsinstance into a JSON formatted StringBuildertargetwith the specifiedindentof spaces.- Parameters:
target- AStringBuilderto write the JSON inmargin- The margin of spaces to indent the resulting block of JSON
-
toYaml
public static void toYaml(manifold.rt.api.Bindings thiz, StringBuilder target)Serializes thisBindingsinstance into a YAML 1.2 formatted StringBuildertargetwith the specifiedindentof spaces.- Parameters:
target- AStringBuilderto write the YAML in
-
listToJson
public static void listToJson(StringBuilder target, int indent, List value)
Utility to serialize aListcomposed of JSON values, where a JSON value is one of:- a simple type such as a String, number, or boolean
- a
Bindingsof property names to JSON values - a
Listcomposed of JSON values
- Parameters:
target- AStringBuilderto write the JSON inindent- The margin of spaces to indent the JSONvalue- AListcomposed 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 callinglistToJson(StringBuilder, int, List)with no indentation and returns a String.
-
toXml
public static String toXml(manifold.rt.api.Bindings thiz)
Serializes thisBindingsinstance to XML nested in a root element named"object"
-
toXml
public static String toXml(manifold.rt.api.Bindings thiz, String name)
Serializes thisBindingsinstance to XML with in a root element with the specifiedname- 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 thisBindingsinstance into an XML formatted StringBuildertargetwith the specifiedindentof spaces.- Parameters:
name- The name of the root element to nest the Bindings XMLtarget- AStringBuilderto write the XML inindent- The margin of spaces to indent the XML
-
toCsv
public static String toCsv(manifold.rt.api.Bindings thiz)
Serializes thisBindingsinstance to CSV nested in a root element named"object"
-
toCsv
public static String toCsv(manifold.rt.api.Bindings thiz, String name)
Serializes thisBindingsinstance to CSV with in a root element with the specifiedname- 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 thisBindingsinstance into an CSV formatted StringBuildertargetwith the specifiedindentof spaces.- Parameters:
name- The name of the root element to nest the Bindings CSVtarget- AStringBuilderto write the CSV inindent- 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 thisBindings. URL encodes the arguments in UTF-8 and appends them to the list using standard URL query delimiters. If an argument is aBindingsor aList, 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 thisBindings- 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 thisBindingsto 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 thisBindingsto 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 thisBindingsusing aDataBindingsfor 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 thisBindings. Note this method assumes the Bindings is limited to a JSON styleBindings<String, Value>whereValuetype is strictly:- a
String,Number, orBoolean - a
ListofValue - a
BindingsofStringtoValue
- Parameters:
bindingsSupplier- Creates theBindingsinstance used for the copy and instances for nestedBindings.- Returns:
- A deep copy of this
Bindings
- a
-
-