public abstract class AbstractModel extends Object
This class provides utility methods for serializing to and deserializing from JSON, managing customized parameters, and handling HTTP headers and requests.
Modifier and Type | Field and Description |
---|---|
Map<String,String> |
header
Stores HTTP headers for the request.
|
protected boolean |
skipSign
Flag to indicate whether to skip signing for this request.
|
Constructor and Description |
---|
AbstractModel() |
Modifier and Type | Method and Description |
---|---|
HashMap<String,Object> |
any()
Get all custom key-value pairs from this model.
|
static <O> O |
fromJsonString(String json,
Class<O> cls)
Deserialize a JSON string into an object of a subclass of AbstractModel.
|
protected String[] |
getBinaryParams()
Mark which parameters are binary type (for multipart requests).
|
Map<String,String> |
GetHeader()
Get the HTTP request headers.
|
protected HashMap<String,byte[]> |
getMultipartRequestParams()
Return the multipart request parameters (if any).
|
boolean |
getSkipSign()
Get the flag indicating whether the sign should be skipped.
|
boolean |
isStream()
Check if the model is a stream type.
|
void |
set(String key,
Object value)
Set any custom key-value pair to this model.
|
void |
SetHeader(Map<String,String> header)
Set the HTTP request headers.
|
protected <V extends AbstractModel> |
setParamArrayObj(HashMap<String,String> map,
String prefix,
V[] array)
Helper method to set an array of object parameters in the map.
|
protected <V> void |
setParamArraySimple(HashMap<String,String> map,
String prefix,
V[] array)
Helper method to set an array of simple parameters in the map.
|
protected <V extends AbstractModel> |
setParamObj(HashMap<String,String> map,
String prefix,
V obj)
Helper method to set an object parameter in the map.
|
protected <V> void |
setParamSimple(HashMap<String,String> map,
String key,
V value)
Helper method to set a simple parameter in the map.
|
void |
setSkipSign(boolean skipSign)
Set the flag indicating whether the sign should be skipped.
|
static <O extends AbstractModel> |
toJsonString(O obj)
Convert an object of type O to its JSON string representation.
|
protected abstract void |
toMap(HashMap<String,String> map,
String prefix)
Abstract method to be implemented by subclasses.
|
protected boolean skipSign
public static <O extends AbstractModel> String toJsonString(O obj)
O
- The type of the object.obj
- The object to be serialized to JSON.public static <O> O fromJsonString(String json, Class<O> cls)
O
- The type of the object to deserialize.json
- The JSON string to be deserialized.cls
- The class of the target model type.protected abstract void toMap(HashMap<String,String> map, String prefix)
map
- The map to populate with the model's parameters.prefix
- A string prefix for the keys.protected String[] getBinaryParams()
protected HashMap<String,byte[]> getMultipartRequestParams()
protected <V> void setParamSimple(HashMap<String,String> map, String key, V value)
V
- The type of the value.map
- The map to put the parameter into.key
- The key for the parameter.value
- The value of the parameter.protected <V> void setParamArraySimple(HashMap<String,String> map, String prefix, V[] array)
V
- The type of the values in the array.map
- The map to put the parameters into.prefix
- The prefix for each key.array
- The array of values.protected <V extends AbstractModel> void setParamObj(HashMap<String,String> map, String prefix, V obj)
V
- The type of the object.map
- The map to put the parameter into.prefix
- The prefix for the key.obj
- The object to add to the map.protected <V extends AbstractModel> void setParamArrayObj(HashMap<String,String> map, String prefix, V[] array)
V
- The type of the objects in the array.map
- The map to put the parameters into.prefix
- The prefix for each key.array
- The array of object values.public void set(String key, Object value)
key
- The key to set.value
- The value to set.public HashMap<String,Object> any()
public boolean getSkipSign()
public void setSkipSign(boolean skipSign)
skipSign
- True to skip the sign; false otherwise.public Map<String,String> GetHeader()
public void SetHeader(Map<String,String> header)
header
- A map of HTTP headers to set.public boolean isStream()
Copyright © 2025. All rights reserved.