public class JSONPObject
extends java.lang.Object
JSONP is a technique for safely requesting data from another domain. It wraps JSON data in a function call to bypass the same-origin policy that prevents direct access to resources from different domains.
Example usage:
// Create a JSONP object
JSONPObject jsonp = new JSONPObject("callback");
jsonp.addParameter(new JSONObject().fluentPut("id", 1).fluentPut("name", "test"));
// Serialize to JSONP string
String jsonpString = jsonp.toString(); // "callback({\"id\":1,\"name\":\"test\"})"
// Parse from JSONP string
JSONPObject parsed = JSON.parseObject(jsonpString, JSONPObject.class);
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
function
The function name for JSONP callback
|
private java.util.List<java.lang.Object> |
parameters
The parameters for JSONP function call
|
| Constructor and Description |
|---|
JSONPObject()
Default constructor for JSONPObject
|
JSONPObject(java.lang.String function)
Constructor with function name
|
| Modifier and Type | Method and Description |
|---|---|
void |
addParameter(java.lang.Object parameter)
Adds a parameter to this JSONP object
|
java.lang.String |
getFunction()
Gets the function name of this JSONP object
|
java.util.List<java.lang.Object> |
getParameters()
Gets the parameters list of this JSONP object
|
void |
setFunction(java.lang.String function)
Sets the function name of this JSONP object
|
java.lang.String |
toString()
Serializes this JSONP object to JSONP string format
|
private java.lang.String function
private final java.util.List<java.lang.Object> parameters
public JSONPObject()
public JSONPObject(java.lang.String function)
function - the JSONP callback function namepublic java.lang.String getFunction()
public void setFunction(java.lang.String function)
function - the function name to setpublic java.util.List<java.lang.Object> getParameters()
public void addParameter(java.lang.Object parameter)
parameter - the parameter to addpublic java.lang.String toString()
toString in class java.lang.Object