本文整理汇总了Java中net.sf.json.JSONNull类的典型用法代码示例。如果您正苦于以下问题:Java JSONNull类的具体用法?Java JSONNull怎么用?Java JSONNull使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONNull类属于net.sf.json包,在下文中一共展示了JSONNull类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import net.sf.json.JSONNull; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void execute() {
JSONObject postDifferentialCommentResult = postDifferentialComment(comment, SILENT,
commentAction);
if (postDifferentialCommentResult == null ||
!(postDifferentialCommentResult.get("error_info") instanceof JSONNull)) {
if (postDifferentialCommentResult != null) {
info(String.format("Got error %s with action %s",
postDifferentialCommentResult.get("error_info"), commentAction));
}
info("Re-trying with action 'none'");
postDifferentialComment(comment, SILENT, DEFAULT_COMMENT_ACTION);
}
}
示例2: getParentCoverage
import net.sf.json.JSONNull; //导入依赖的package包/类
public CodeCoverageMetrics getParentCoverage(String sha) {
if (sha == null) {
return null;
}
try {
String coverageJSON = getCoverage(sha);
JsonSlurper jsonParser = new JsonSlurper();
JSON responseJSON = jsonParser.parseText(coverageJSON);
if (responseJSON instanceof JSONNull) {
return null;
}
JSONObject coverage = (JSONObject) responseJSON;
return new CodeCoverageMetrics(
((Double) coverage.getDouble(PACKAGE_COVERAGE_KEY)).floatValue(),
((Double) coverage.getDouble(FILES_COVERAGE_KEY)).floatValue(),
((Double) coverage.getDouble(CLASSES_COVERAGE_KEY)).floatValue(),
((Double) coverage.getDouble(METHOD_COVERAGE_KEY)).floatValue(),
((Double) coverage.getDouble(LINE_COVERAGE_KEY)).floatValue(),
((Double) coverage.getDouble(CONDITIONAL_COVERAGE_KEY)).floatValue());
} catch (Exception e) {
e.printStackTrace(logger.getStream());
}
return null;
}
示例3: test_for_issue
import net.sf.json.JSONNull; //导入依赖的package包/类
public void test_for_issue() throws Exception {
Model model = new Model();
model.object = JSONNull.getInstance();
System.out.println(JSON.toJSONString(model));
// System.out.println(JSON.toJSONString(map));
}
示例4: query
import net.sf.json.JSONNull; //导入依赖的package包/类
/**
* Execute Http request and response code
* @param request - HTTP Request
* @param expectedCode - expected response code
* @return - response in JSONObject
*/
public JSON query(HttpRequestBase request, int expectedCode) throws IOException {
log.info("Requesting: " + request);
addRequiredHeader(request);
HttpParams requestParams = request.getParams();
requestParams.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, TIMEOUT * 1000);
requestParams.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, TIMEOUT * 1000);
synchronized (httpClient) {
String response;
try {
HttpResponse result = httpClient.execute(request);
int statusCode = result.getStatusLine().getStatusCode();
response = getResponseEntity(result);
if (statusCode != expectedCode) {
notifier.notifyAbout("Response with code " + statusCode + ": " + extractErrorMessage(response));
throw new IOException("API responded with wrong status code: " + statusCode);
} else {
log.debug("Response: " + response);
}
} finally {
request.abort();
}
if (response == null || response.isEmpty()) {
return JSONNull.getInstance();
} else {
return JSONSerializer.toJSON(response, new JsonConfig());
}
}
}
示例5: sendMessage
import net.sf.json.JSONNull; //导入依赖的package包/类
/**
* Try to send a message to harbormaster
* @param unitResults the unit testing results to send
* @param coverage the coverage data to send
* @return false if an error was encountered
*/
private boolean sendMessage(UnitResults unitResults, Map<String, String> coverage, LintResults lintResults) throws IOException, ConduitAPIException {
JSONObject result = diffClient.sendHarbormasterMessage(phid, harbormasterSuccess, unitResults, coverage, lintResults);
if (result.containsKey("error_info") && !(result.get("error_info") instanceof JSONNull)) {
info(String.format("Error from Harbormaster: %s", result.getString("error_info")));
failTask();
return false;
} else {
this.result = Result.SUCCESS;
}
return true;
}
示例6: getBranch
import net.sf.json.JSONNull; //导入依赖的package包/类
/**
* Return the local branch name
*
* @return the name of the branch, or unknown
*/
public String getBranch() {
Object branchName = rawJSON.get("branch");
if (branchName instanceof JSONNull) {
return "(none)";
}
try {
return (String) branchName;
} catch (ClassCastException e) {
return "(unknown)";
}
}
示例7: testGetBranchWithEmptyResponse
import net.sf.json.JSONNull; //导入依赖的package包/类
@Test
public void testGetBranchWithEmptyResponse() throws Exception {
JSONObject empty = new JSONObject();
empty.put("branch", JSONNull.getInstance());
Differential diff = new Differential(empty);
assertEquals("(none)", diff.getBranch());
}
示例8: put
import net.sf.json.JSONNull; //导入依赖的package包/类
public final MapTuple put(final String field, final @Nullable Object obj) {
if (obj == null) {
/*
* We need this because of joins. We don't use Java null because
* too many libraries either return null to represent absence,
* don't allow null entries, or use null to represent something else.
*/
_values.put(field, JSONNull.getInstance());
} else {
_values.put(field, obj);
}
return this; // for chaining
}
示例9: removeNulls
import net.sf.json.JSONNull; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static void removeNulls(JSONObject json) {
Iterator<String> keyIter = json.keys();
while(keyIter.hasNext()) {
String key = keyIter.next().toString();
if (json.get(key) instanceof JSONNull || json.get(key) == null) {
json.remove(key);
}
}
}
示例10: parseObj
import net.sf.json.JSONNull; //导入依赖的package包/类
public static JSONObject parseObj(String o) {
JSON j = JSONSerializer.toJSON(o);
if (j instanceof JSONNull) {
return null;
} else {
return (JSONObject)j;
}
}
示例11: parseArray
import net.sf.json.JSONNull; //导入依赖的package包/类
public static JSONArray parseArray(String o) {
JSON j = JSONSerializer.toJSON(o);
if (j instanceof JSONNull) {
return null;
} else {
return (JSONArray)j;
}
}
示例12: getStringForType
import net.sf.json.JSONNull; //导入依赖的package包/类
public static String getStringForType(Object value) {
if(value instanceof String) {
return "\""+ StringEscapeUtils.escapeJson((String)value) +"\"";
} else if(value instanceof Integer || value instanceof Float || value instanceof Long || value instanceof Boolean) {
return value.toString();
} else if(value instanceof JSONArray) {
return JSONUtil.toString((JSONArray) value);
} else if(value instanceof JSONObject) {
return JSONUtil.toString((JSONObject) value);
} else if(value instanceof JSONNull || value == null) {
return "null";
} else {
throw new RuntimeException("unrecognized type for value: "+value+"["+value.getClass().getName()+"]");
}
}
示例13: configure
import net.sf.json.JSONNull; //导入依赖的package包/类
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
// To persist global configuration information,
// set that to properties and call save().
Object identities = formData.get("chefIdentity");
if (!JSONNull.getInstance().equals(identities)) {
chefIdentities = req.bindJSONToList(ChefIdentity.class, identities);
} else {
chefIdentities = null;
}
save();
return super.configure(req,formData);
}
示例14: configure
import net.sf.json.JSONNull; //导入依赖的package包/类
@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
Object s = json.get("servers");
if (!JSONNull.getInstance().equals(s)) {
servers = req.bindJSONToList(Server.class, s);
} else {
servers = null;
}
publicKeyPath = json.getString("publicKeyPath");
save();
return super.configure(req, json);
}
示例15: convertElement
import net.sf.json.JSONNull; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public Vertex convertElement(Object json, Network network) {
try {
if (json == null) {
return null;
}
Vertex object = null;
if (json instanceof JSONObject) {
object = network.createVertex();
for (Iterator iterator = ((JSONObject)json).keys(); iterator.hasNext(); ) {
String name = (String)iterator.next();
Object value = ((JSONObject)json).get(name);
if (value == null) {
continue;
}
Primitive key = new Primitive(name);
Vertex target = convertElement(value, network);
object.addRelationship(key, target);
}
} else if (json instanceof JSONArray) {
object = network.createInstance(Primitive.ARRAY);
JSONArray array = (JSONArray)json;
for (int index = 0; index < array.size(); index++) {
Vertex element = convertElement(array.get(index), network);
object.addRelationship(Primitive.ELEMENT, element, index);
}
} else if (json instanceof JSONNull) {
object = network.createInstance(Primitive.NULL);
} else if (json instanceof String) {
object = network.createVertex(json);
} else if (json instanceof Number) {
object = network.createVertex(json);
} else if (json instanceof Date) {
object = network.createVertex(json);
} else if (json instanceof Boolean) {
object = network.createVertex(json);
} else {
log("Unknown JSON object", Level.INFO, json);
}
return object;
} catch (Exception exception) {
log(exception);
return null;
}
}