本文整理匯總了Java中com.fasterxml.jackson.databind.util.JSONPObject類的典型用法代碼示例。如果您正苦於以下問題:Java JSONPObject類的具體用法?Java JSONPObject怎麽用?Java JSONPObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JSONPObject類屬於com.fasterxml.jackson.databind.util包,在下文中一共展示了JSONPObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: searchAPIJSONP
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
@RequestMapping(value = "/search", method = RequestMethod.GET, produces = "application/javascript")
public ResponseEntity<JSONPObject> searchAPIJSONP(
@RequestParam(value = "query", required = false) String query,
@RequestParam(value = "limit", required = false, defaultValue = "24") Integer limit,
@RequestParam(value = "start", required = false, defaultValue = "0") Integer start,
@RequestParam(value = "facet", required = false) @FacetRequestFormat List<FacetRequest> facets,
@RequestParam(value = "x1", required = false) Double x1,
@RequestParam(value = "y1", required = false) Double y1,
@RequestParam(value = "x2", required = false) Double x2,
@RequestParam(value = "y2", required = false) Double y2,
@RequestParam(value = "sort", required = false) String sort,
@RequestParam(value = "callback", required = true) String callback,
Model model) throws SolrServerException {
spatial(query,x1, y1, x2, y2, null, limit,start,facets,sort,null,model);
return new ResponseEntity<JSONPObject>(new JSONPObject(callback,(Page) model.asMap().get("result")),HttpStatus.OK);
}
示例2: serializeToJSONPString
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* Serializes the given object and wraps it in a callback function
* i.e. <callback>(<json>)
* Note: This will not append a trailing semicolon
* @param callback The name of the Javascript callback to prepend
* @param object The object to serialize
* @return A JSONP formatted string
* @throws IllegalArgumentException if the callback method name was missing
* or object was null
* @throws JSONException if the object could not be serialized
*/
public static final String serializeToJSONPString(final String callback,
final Object object) {
if (callback == null || callback.isEmpty())
throw new IllegalArgumentException("Missing callback name");
if (object == null)
throw new IllegalArgumentException("Object was null");
try {
return jsonMapper.writeValueAsString(new JSONPObject(callback, object));
} catch (JsonProcessingException e) {
throw new JSONException(e);
}
}
示例3: formatResponse
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* This method takes an object and creates a <code>Response</code> object
* out of it which will be returned. If <code>messages</code> contains error
* messages they will be send back instead.
* The format of the <code>Response</code>
* depends on the <code>responseType</code>.
* Supported types are <code>application/xml</code> and <code>application/json</code>
*
* @param respondData an object which will be returned as a
* <code>Response</code> object
* @param messages a list of <code>Message</code> objects which contain
* error messages of the API request
* @param callback if set and responseType is json the result will be returned
* via this javascript callback function (optional)
* @return a <code>Response</code> object containing the <code>responseData</code>
* in the format defined with <code>responseType</code>
*/
private Response formatResponse(Object respondData,
List<Message> messages,
String serviceName,
String callback) {
//handle error messages if existing
if (messages.size() > 0) {
throw new EasyRecException(messages, serviceName, WS.RESPONSE_TYPE_JSON, callback);
}
if (respondData instanceof List) {
respondData = new ResponseSuccessMessage(serviceName, (List<SuccessMessage>) respondData);
}
//convert respondData to Respond object
if (callback != null) {
return Response.ok(new JSONPObject(callback, respondData),
WS.RESPONSE_TYPE_JSCRIPT).build();
} else {
return Response.ok(respondData, WS.RESPONSE_TYPE_JSON).build();
}
}
示例4: unread
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* 按應用獲取未讀消息對象
*/
@RequestMapping("/unread/{userId}")
@ResponseBody
public JSONPObject unread(@PathVariable("userId") String userId,
@RequestParam(value = "jsonp") String function) {
Map<String, Object> result = new LinkedHashMap<>();
int totalUnread = getTotalUnread(userId);
result.put("totalUnread", totalUnread);
if (totalUnread > 0) {
History example = new History();
example.userId = userId;
example.unread = true;
example.ack = false;
example.limit = totalUnread;
History history = timelineService.find(example);
result.put("messages", history.messages);
}
return new JSONPObject(function, result);
}
示例5: doGet
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("application/json");
if (servletPlugin.getMetricsServletAllowedOrigin() != null) {
resp.setHeader("Access-Control-Allow-Origin", servletPlugin.getMetricsServletAllowedOrigin());
}
resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
resp.setStatus(HttpServletResponse.SC_OK);
final OutputStream output = resp.getOutputStream();
try {
String jsonpParamName = servletPlugin.getMetricsServletJsonpParamName();
if (jsonpParamName != null && req.getParameter(jsonpParamName) != null) {
getWriter(req).writeValue(output, new JSONPObject(req.getParameter(jsonpParamName), registry));
} else {
getWriter(req).writeValue(output, registry);
}
} finally {
output.close();
}
}
示例6: getPartyEntitiesByType
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* TODO: replace JSONWithPadding to JSONPObject
*/
@GET
@Path("search")
@Produces(MediaType.APPLICATION_JSON)
public JSONPObject getPartyEntitiesByType(
@QueryParam("callback") String callback,
@QueryParam("typeId") long typeId, @QueryParam("q") String q) {
String hql = "from PartyEntity where partyType.id=? and name like ? order by name";
Page page = partyEntityManager.pagedQuery(hql, 1, DFAULT_PAGE_SIZE,
typeId, q.replace("_", "\\_") + "%");
List<PartyEntity> partyEntities = (List<PartyEntity>) page.getResult();
List<PartyEntityDTO> partyEntityDtos = new ArrayList<PartyEntityDTO>();
for (PartyEntity partyEntity : partyEntities) {
PartyEntityDTO partyEntityDto = new PartyEntityDTO();
partyEntityDto.setId(partyEntity.getId());
partyEntityDto.setName(partyEntity.getName());
partyEntityDtos.add(partyEntityDto);
}
return new JSONPObject(callback, partyEntityDtos);
}
示例7: jsonpInfo
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
@RequestMapping(value = "/jsonpInfo", method = {RequestMethod.GET})
@ResponseBody
public Object jsonpInfo(String callback, String userId) throws IOException {
UUser user = userFService.getUserById(userId);
JSONPObject jsonpObject = new JSONPObject(callback, user);
return jsonpObject;
}
示例8: serializeToJSONPBytes
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* Serializes the given object and wraps it in a callback function
* i.e. <callback>(<json>)
* Note: This will not append a trailing semicolon
* @param callback The name of the Javascript callback to prepend
* @param object The object to serialize
* @return A JSONP formatted byte array
* @throws IllegalArgumentException if the callback method name was missing
* or object was null
* @throws JSONException if the object could not be serialized
* @throws IOException Thrown when there was an issue reading the object
*/
public static final byte[] serializeToJSONPBytes(final String callback,
final Object object) {
if (callback == null || callback.isEmpty())
throw new IllegalArgumentException("Missing callback name");
if (object == null)
throw new IllegalArgumentException("Object was null");
try {
return jsonMapper.writeValueAsBytes(new JSONPObject(callback, object));
} catch (JsonProcessingException e) {
throw new JSONException(e);
}
}
示例9: jsonpInfo
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
@RequestMapping(value = "/jsonpInfo",method = { RequestMethod.GET })
@ResponseBody
public Object jsonpInfo(String callback,Integer userId) throws IOException {
User user = userService.getUserById(userId);
JSONPObject jsonpObject = new JSONPObject(callback,user) ;
return jsonpObject ;
}
示例10: EasyRecException
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
public EasyRecException(List<Message> messages, String action, String type, String callback) {
//GenericEntity<List<Message>> entity = new GenericEntity<List<Message>>(messages) {};
super(callback != null ?
Response.ok(new JSONPObject(callback, messagesToArray(messages)),
WS.RESPONSE_TYPE_JSCRIPT).build() :
Response.ok(messagesToArray(messages), type).build());
}
示例11: formatResponse
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* This method takes an object and creates a <code>Response</code> object
* out of it which will be returned. If <code>messages</code> contains error
* messages they will be send back instead.
* The format of the <code>Response</code>
* depends on the <code>responseType</code>.
* Supported types are <code>application/xml</code> and <code>application/json</code>
*
* @param respondData an object which will be returned as a
* <code>Response</code> object
* @param messages a list of <code>Message</code> objects which contain
* error messages of the API request
* @param responseType defines the format of the <code>Response</code> object
* @param callback if set and responseType is json the result will be returned
* via this javascript callback function (optional)
* @return a <code>Response</code> object containing the <code>responseData</code>
* in the format defined with <code>responseType</code>
*/
private Response formatResponse(Object respondData,
List<Message> messages,
String serviceName,
String responseType,
String callback) {
//handle error messages if existing
if (messages.size() > 0) {
if ((WS.RESPONSE_TYPE_PATH_JSON.equals(responseType)))
throw new EasyRecException(messages, serviceName, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, serviceName);
}
if (respondData instanceof List) {
respondData = new ResponseSuccessMessage(serviceName, (List<SuccessMessage>) respondData);
}
//convert respondData to Respond object
if (WS.RESPONSE_TYPE_PATH_JSON.equals(responseType)) {
if (callback != null) {
return Response.ok(new JSONPObject(callback, respondData),
WS.RESPONSE_TYPE_JSCRIPT).build();
} else {
return Response.ok(respondData, WS.RESPONSE_TYPE_JSON).build();
}
} else if (WS.RESPONSE_TYPE_PATH_XML.equals(responseType)) {
return Response.ok(respondData, WS.RESPONSE_TYPE_XML).build();
} else {
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
}
示例12: formatResponse
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* This method takes an object and creates a <code>Response</code> object
* out of it which will be returned. If <code>messages</code> contains error
* messages they will be send back instead.
* The format of the <code>Response</code>
* depends on the <code>responseType</code>.
* Supported types are <code>application/xml</code> and <code>application/json</code>
*
* @param respondData an object which will be returned as a
* <code>Response</code> object
* @param messages a list of <code>Message</code> objects which contain
* error messages of the API request
* @param responseType defines the format of the <code>Response</code> object
* @param callback if set and responseType is jason the result will be returned
* via this javascript callback function (optional)
* @return a <code>Response</code> object containing the <code>responseData</code>
* in the format defined with <code>responseType</code>
*/
private Response formatResponse(Object respondData,
List<Message> messages,
String serviceName,
String responseType,
String callback) {
//handle error messages if existing
if (messages.size() > 0) {
if (responseType.endsWith(WS.RESPONSE_TYPE_PATH_JSON))
throw new EasyRecException(messages, serviceName, WS.RESPONSE_TYPE_JSON, callback);
else
throw new EasyRecException(messages, serviceName);
}
if (respondData instanceof List) {
respondData = new ResponseSuccessMessage(serviceName, (List<SuccessMessage>) respondData);
}
//convert respondData to Respond object
if (responseType.endsWith(WS.RESPONSE_TYPE_PATH_JSON)) {
if (callback != null) {
return Response.ok(new JSONPObject(callback, respondData),
WS.RESPONSE_TYPE_JSCRIPT).build();
} else {
return Response.ok(respondData, WS.RESPONSE_TYPE_JSON).build();
}
} else if (WS.XML_PATH.equals(responseType)) {
return Response.ok(respondData, WS.RESPONSE_TYPE_XML).build();
} else {
return Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build();
}
}
示例13: toJsonP
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
@Override
public void toJsonP( OutputStream output, Object value, String callback )
throws IOException
{
if ( StringUtils.isEmpty( callback ) )
{
callback = "callback";
}
jsonMapper.writeValue( output, new JSONPObject( callback, value ) );
}
示例14: getJsonP
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
/**
* @param identifier
* Set the identifier of the image
* @return A model and view containing a image
*/
@RequestMapping(value = "/{identifier}",
params = "callback",
method = RequestMethod.GET,
produces = "application/javascript")
public ResponseEntity<JSONPObject> getJsonP(@PathVariable String identifier, @RequestParam(value = "fetch", required = false) String fetch,
@RequestParam(value = "callback", required = true) String callback) {
return new ResponseEntity<JSONPObject>(new JSONPObject(callback,service.find(identifier,fetch)), HttpStatus.OK);
}
示例15: getJsonP
import com.fasterxml.jackson.databind.util.JSONPObject; //導入依賴的package包/類
@RequestMapping(value = "/{identifier}",
params = "callback",
method = RequestMethod.GET,
produces = "application/javascript")
public ResponseEntity<JSONPObject> getJsonP(@PathVariable String identifier, @RequestParam(value = "fetch", required = false) String fetch,
@RequestParam(value = "callback", required = true) String callback) {
return new ResponseEntity<JSONPObject>(new JSONPObject(callback,service.find(identifier,fetch)), HttpStatus.OK);
}