Package com.alibaba.dashscope.transport
Class JsonSupport
java.lang.Object
com.alibaba.dashscope.transport.JsonSupport
Shared Jackson mapper and wire-envelope helpers. Single mapper instance per JVM.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Iterable<com.fasterxml.jackson.databind.JsonNode>arrayElements(com.fasterxml.jackson.databind.JsonNode node) Shallow iterable over array elements; empty when the node is not an array.static StringerrorCode(com.fasterxml.jackson.databind.JsonNode body) Wire error code: top-level "code", else nested error.code / error.type.static com.fasterxml.jackson.databind.node.ObjectNodeerrorFrame(String code, String message, String requestId) Synthetic error frame for failures whose wire body carried no usable error code (e.g. a gateway HTML error page): guaranteesraiseOnError(false)responses still reportisError()true.static StringerrorMessage(com.fasterxml.jackson.databind.JsonNode body) Wire error message: top-level "message", else nested error.message.static StringfindRequestId(Map<String, ?> headers) First non-empty value of x-request-id, x-dashscope-requestid or x-dashscope-request-id.static com.fasterxml.jackson.databind.node.ObjectNodeflattenEnvelope(com.fasterxml.jackson.databind.JsonNode body) Liftbody.outputto the top level so public types stay flat (Python v2flatten_envelopeparity).static booleanisErrorFrame(com.fasterxml.jackson.databind.JsonNode body) A frame is an error frame when it carries a top-level "code" or a nested "error" object with code/type/message.static com.fasterxml.jackson.databind.ObjectMappermapper()static com.fasterxml.jackson.databind.JsonNodestatic com.fasterxml.jackson.databind.JsonNodeparseErrorBody(String text) Parse an error response body, preferring a plain JSON object; falls back to extracting the error frame from SSE-shaped text (older gateways answer streaming requests with SSE frames even on failure).static com.fasterxml.jackson.databind.JsonNodestatic com.fasterxml.jackson.databind.JsonNodestatic Stringrequest_id from the body, else the first known request id header.static StringrequestIdOrUnknown(String requestId) static ObjecttoPlainValue(com.fasterxml.jackson.databind.JsonNode node) Convert a JsonNode to plain Java values (Map/List/scalars) for exception bodies.
-
Method Details
-
mapper
public static com.fasterxml.jackson.databind.ObjectMapper mapper() -
readTree
-
readTree
-
parseErrorBody
Parse an error response body, preferring a plain JSON object; falls back to extracting the error frame from SSE-shaped text (older gateways answer streaming requests with SSE frames even on failure). Never throws: unparseable bodies yield null. -
isErrorFrame
public static boolean isErrorFrame(com.fasterxml.jackson.databind.JsonNode body) A frame is an error frame when it carries a top-level "code" or a nested "error" object with code/type/message. -
errorCode
Wire error code: top-level "code", else nested error.code / error.type. -
errorMessage
Wire error message: top-level "message", else nested error.message. -
requestId
request_id from the body, else the first known request id header. -
findRequestId
First non-empty value of x-request-id, x-dashscope-requestid or x-dashscope-request-id. -
requestIdOrUnknown
-
toPlainValue
Convert a JsonNode to plain Java values (Map/List/scalars) for exception bodies. -
flattenEnvelope
public static com.fasterxml.jackson.databind.node.ObjectNode flattenEnvelope(com.fasterxml.jackson.databind.JsonNode body) Liftbody.outputto the top level so public types stay flat (Python v2flatten_envelopeparity). Envelope keys win — howrequest_id/code/messagereach the flattened node; null envelope values are dropped so an absent field cannot overwrite a real payload value. -
errorFrame
public static com.fasterxml.jackson.databind.node.ObjectNode errorFrame(String code, String message, String requestId) Synthetic error frame for failures whose wire body carried no usable error code (e.g. a gateway HTML error page): guaranteesraiseOnError(false)responses still reportisError()true. -
missingNode
public static com.fasterxml.jackson.databind.JsonNode missingNode() -
arrayElements
public static Iterable<com.fasterxml.jackson.databind.JsonNode> arrayElements(com.fasterxml.jackson.databind.JsonNode node) Shallow iterable over array elements; empty when the node is not an array.
-