本文整理了Java中org.json.simple.JSONObject.isEmpty()
方法的一些代码示例,展示了JSONObject.isEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.isEmpty()
方法的具体详情如下:
包路径:org.json.simple.JSONObject
类名称:JSONObject
方法名:isEmpty
暂无
代码示例来源:origin: apache/metron
public static JSONObject adjustKeys(JSONObject enrichedMessage, JSONObject enrichedField, String field, String prefix) {
if ( !enrichedField.isEmpty()) {
for (Object enrichedKey : enrichedField.keySet()) {
if(!StringUtils.isEmpty(prefix)) {
enrichedMessage.put(field + "." + enrichedKey, enrichedField.get(enrichedKey));
}
else {
enrichedMessage.put(enrichedKey, enrichedField.get(enrichedKey));
}
}
}
return enrichedMessage;
}
代码示例来源:origin: rhuss/jolokia
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
int i = 0;
for(Map.Entry entry : pMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
ret.put(entry.getKey(),
pConverter.extractObject(entry.getValue(), paths, jsonify));
if (++i > pLength) {
break;
}
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Filtered out ...
}
}
if (ret.isEmpty() && pLength > 0) {
// Not a single value passed the filter
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: rhuss/jolokia
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
Object value = entry.getValue().extract(pValue);
ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify));
} catch (AttributeExtractor.SkipAttributeException e) {
// Skip this one ...
continue;
} catch (ValueFaultHandler.AttributeFilteredException e) {
// ... and this, too
continue;
}
}
if (ret.isEmpty()) {
// Everything filtered, bubble up ...
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: rhuss/jolokia
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter)
throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Object rowObject : pTd.values()) {
CompositeData row = (CompositeData) rowObject;
Stack<String> path = (Stack<String>) pExtraArgs.clone();
Object keyObject = row.get("key");
if (keyObject != null) {
try {
Object value = pConverter.extractObject(row.get("value"), path, true);
ret.put(keyObject.toString(), value);
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Skip to next object since attribute was filtered
}
}
}
if (!pTd.isEmpty() && ret.isEmpty()) {
// Bubble up if not a single thingy has been found
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: rhuss/jolokia
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (String key : (Set<String>) pData.getCompositeType().keySet()) {
Stack<String> path = (Stack<String>) pPath.clone();
try {
ret.put(key, pConverter.extractObject(pData.get(key), path, true));
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Ignore this key;
}
}
if (ret.isEmpty()) {
// If every key was filtered, this composite data should be skipped completely
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: apache/metron
_LOG.debug("[Metron] Cleaned message: {}", cleanedMessage);
if (cleanedMessage == null || cleanedMessage.isEmpty()) {
throw new Exception("Unable to clean message: " + rawMessage);
代码示例来源:origin: apache/metron
enrichedMessage.put("adapter." + adapter.getClass().getSimpleName().toLowerCase() + ".begin.ts", "" + System.currentTimeMillis());
try {
if (rawMessage == null || rawMessage.isEmpty())
throw new Exception("Could not parse binary stream to JSON");
if (key == null)
if (!enrichedMessage.isEmpty()) {
collector.emit(enrichmentType, new Values(key, enrichedMessage, subGroup));
代码示例来源:origin: apache/metron
/**
* Ensures that if we try to transform with a field which does not exist, it does not
* 1. throw an exception
* 2. do any transformation.
*/
@Test
public void testStellar_negative() throws Exception {
SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(stellarConfig));
FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);
//no input fields => no transformation
JSONObject input = new JSONObject(new HashMap<String, Object>() {{
}});
handler.transformAndUpdate(input, Context.EMPTY_CONTEXT());
Assert.assertFalse(input.containsKey("utc_timestamp"));
Assert.assertTrue(input.isEmpty());
}
代码示例来源:origin: OpenNMS/opennms
/**
* concerts all time values into a normalised time in memo json object from database
* example timestamps to translate
* {
* "suppressedtime":"2016-08-04 16:11:16.01+01",
* "suppresseduntil":"2016-08-04 16:11:16.01+01",
* "lasteventtime":"2016-08-04 16:11:16.01+01",
* "alarmacktime":"2016-08-04 07:34:04.617+01",
* "firsteventtime":"2016-08-04 16:11:16.01+01",
* "firstautomationtime":"2016-08-04 16:12:03.272205+01",
* "lastautomationtime":"2016-08-04 16:12:03.272205+01"
* }
* @param jsonObject
* @return
*/
public JSONObject jsonMemoTimeNormaliser(JSONObject jsonObject){
if(jsonObject.isEmpty()) return jsonObject;
String created= (jsonObject.get("created")==null) ? null : timeNormaliser(jsonObject.get("created").toString());
if (created!=null) jsonObject.put("created", created);
String updated= (jsonObject.get("updated")==null) ? null : timeNormaliser(jsonObject.get("updated").toString());
if (updated!=null) jsonObject.put("suppresseduntil", updated);
return jsonObject;
}
代码示例来源:origin: org.jolokia/jolokia-osgi
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
int i = 0;
for(Map.Entry entry : pMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
ret.put(entry.getKey(),
pConverter.extractObject(entry.getValue(), paths, jsonify));
if (++i > pLength) {
break;
}
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Filtered out ...
}
}
if (ret.isEmpty() && pLength > 0) {
// Not a single value passed the filter
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-core
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
int i = 0;
for(Map.Entry entry : pMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
ret.put(entry.getKey(),
pConverter.extractObject(entry.getValue(), paths, jsonify));
if (++i > pLength) {
break;
}
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Filtered out ...
}
}
if (ret.isEmpty() && pLength > 0) {
// Not a single value passed the filter
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-service-serializer
private JSONObject extractMapValues(ObjectToJsonConverter pConverter, Stack<String> pPathParts, boolean jsonify, Map<Object, Object> pMap, int pLength) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
int i = 0;
for(Map.Entry entry : pMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
ret.put(entry.getKey(),
pConverter.extractObject(entry.getValue(), paths, jsonify));
if (++i > pLength) {
break;
}
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Filtered out ...
}
}
if (ret.isEmpty() && pLength > 0) {
// Not a single value passed the filter
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-service-serializer
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
Object value = entry.getValue().extract(pValue);
ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify));
} catch (AttributeExtractor.SkipAttributeException e) {
// Skip this one ...
continue;
} catch (ValueFaultHandler.AttributeFilteredException e) {
// ... and this, too
continue;
}
}
if (ret.isEmpty()) {
// Everything filtered, bubble up ...
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-core
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
Object value = entry.getValue().extract(pValue);
ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify));
} catch (AttributeExtractor.SkipAttributeException e) {
// Skip this one ...
continue;
} catch (ValueFaultHandler.AttributeFilteredException e) {
// ... and this, too
continue;
}
}
if (ret.isEmpty()) {
// Everything filtered, bubble up ...
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-osgi
private Object extractAll(ObjectToJsonConverter pConverter, T pValue, Stack<String> pPathParts, boolean jsonify) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Map.Entry<String, AttributeExtractor<T>> entry : extractorMap.entrySet()) {
Stack<String> paths = (Stack<String>) pPathParts.clone();
try {
Object value = entry.getValue().extract(pValue);
ret.put(entry.getKey(),pConverter.extractObject(value, paths, jsonify));
} catch (AttributeExtractor.SkipAttributeException e) {
// Skip this one ...
continue;
} catch (ValueFaultHandler.AttributeFilteredException e) {
// ... and this, too
continue;
}
}
if (ret.isEmpty()) {
// Everything filtered, bubble up ...
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-osgi
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter)
throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Object rowObject : pTd.values()) {
CompositeData row = (CompositeData) rowObject;
Stack<String> path = (Stack<String>) pExtraArgs.clone();
Object keyObject = row.get("key");
if (keyObject != null) {
try {
Object value = pConverter.extractObject(row.get("value"), path, true);
ret.put(keyObject.toString(), value);
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Skip to next object since attribute was filtered
}
}
}
if (!pTd.isEmpty() && ret.isEmpty()) {
// Bubble up if not a single thingy has been found
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-core
private Object convertMxBeanMapToJson(TabularData pTd, Stack<String> pExtraArgs, ObjectToJsonConverter pConverter)
throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (Object rowObject : pTd.values()) {
CompositeData row = (CompositeData) rowObject;
Stack<String> path = (Stack<String>) pExtraArgs.clone();
Object keyObject = row.get("key");
if (keyObject != null) {
try {
Object value = pConverter.extractObject(row.get("value"), path, true);
ret.put(keyObject.toString(), value);
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Skip to next object since attribute was filtered
}
}
}
if (!pTd.isEmpty() && ret.isEmpty()) {
// Bubble up if not a single thingy has been found
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-osgi
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (String key : (Set<String>) pData.getCompositeType().keySet()) {
Stack<String> path = (Stack<String>) pPath.clone();
try {
ret.put(key, pConverter.extractObject(pData.get(key), path, true));
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Ignore this key;
}
}
if (ret.isEmpty()) {
// If every key was filtered, this composite data should be skipped completely
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-core
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (String key : (Set<String>) pData.getCompositeType().keySet()) {
Stack<String> path = (Stack<String>) pPath.clone();
try {
ret.put(key, pConverter.extractObject(pData.get(key), path, true));
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Ignore this key;
}
}
if (ret.isEmpty()) {
// If every key was filtered, this composite data should be skipped completely
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
代码示例来源:origin: org.jolokia/jolokia-service-serializer
private Object extractCompleteCdAsJson(ObjectToJsonConverter pConverter, CompositeData pData, Stack<String> pPath) throws AttributeNotFoundException {
JSONObject ret = new JSONObject();
for (String key : (Set<String>) pData.getCompositeType().keySet()) {
Stack<String> path = (Stack<String>) pPath.clone();
try {
ret.put(key, pConverter.extractObject(pData.get(key), path, true));
} catch (ValueFaultHandler.AttributeFilteredException exp) {
// Ignore this key;
}
}
if (ret.isEmpty()) {
// If every key was filtered, this composite data should be skipped completely
throw new ValueFaultHandler.AttributeFilteredException();
}
return ret;
}
内容来源于网络,如有侵权,请联系作者删除!