當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONAware類代碼示例

本文整理匯總了Java中org.json.simple.JSONAware的典型用法代碼示例。如果您正苦於以下問題:Java JSONAware類的具體用法?Java JSONAware怎麽用?Java JSONAware使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSONAware類屬於org.json.simple包,在下文中一共展示了JSONAware類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decorate

import org.json.simple.JSONAware; //導入依賴的package包/類
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    Collection<NodeRef> collection = (Collection<NodeRef>)value;
    JSONArray array = new JSONArray();

    for (NodeRef obj : collection)
    {
        try
        {
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
            jsonObj.put("nodeRef", obj.toString());
            array.add(jsonObj);
        }
        catch (InvalidNodeRefException e)
        {
            logger.warn("Tag with nodeRef " + obj.toString() + " does not exist.");
        }
    }

    return array;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:27,代碼來源:TagPropertyDecorator.java

示例2: decorate

import org.json.simple.JSONAware; //導入依賴的package包/類
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(org.alfresco.service.namespace.QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    Collection<NodeRef> collection = (Collection<NodeRef>)value;
    JSONArray array = new JSONArray();

    for (NodeRef obj : collection)
    {
        try
        {
            JSONObject jsonObj = new JSONObject();
            jsonObj.put("name", this.nodeService.getProperty(obj, ContentModel.PROP_NAME));
            jsonObj.put("path", this.getPath(obj));
            jsonObj.put("nodeRef", obj.toString());
            array.add(jsonObj);
        }
        catch (InvalidNodeRefException e)
        {
            logger.warn("Category with nodeRef " + obj.toString() + " does not exist.");
        }
    }

    return array;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:28,代碼來源:CategoryPropertyDecorator.java

示例3: toString

import org.json.simple.JSONAware; //導入依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public String toString(Object value, Object meta, boolean pretty, boolean insertMeta) {
	return toString(value, meta, insertMeta, (input) -> {
		String json;
		if (input instanceof Map) {
			json = JSONObject.toJSONString((Map) input);
		} else if (input instanceof List) {
			json = JSONArray.toJSONString((List) input);
		} else if (input instanceof JSONAware) {
			json = ((JSONAware) input).toJSONString();
		} else if (input instanceof Set) {
			json = JSONArray.toJSONString(new ArrayList((Set) input));
		} else if (input.getClass().isArray()) {
			json = JSONArray.toJSONString(Arrays.asList(input));
		} else {
			throw new IllegalArgumentException("Unsupported data type (" + input + ")!");
		}
		if (pretty) {
			return JsonBuiltin.format(json);
		}
		return json;
	});
}
 
開發者ID:berkesa,項目名稱:datatree-adapters,代碼行數:25,代碼來源:JsonSimple.java

示例4: encodeO

import org.json.simple.JSONAware; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static JSONAware encodeO(FolderInventoryItem input)
{
    JSONObject out = new JSONObject();

    out.put("name", input.getName());
    out.put("uuid", input.getUuid().toString());

    JSONArray files = input.getFiles().stream()
            .map(FileInventoryItemJSON::encodeO)
            .collect(Collectors.toCollection(JSONArray::new));
    out.put("files", files);

    JSONArray folders = input.getFolders().stream()
            .map(FolderInventoryItemJSON::encodeO)
            .collect(Collectors.toCollection(JSONArray::new));
    out.put("folders", folders);
    return out;
}
 
開發者ID:AstromechZA,項目名稱:bunkr,代碼行數:20,代碼來源:FolderInventoryItemJSON.java

示例5: encodeO

import org.json.simple.JSONAware; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static JSONAware encodeO(Inventory input)
{
    JSONObject out = new JSONObject();
    JSONArray files = input.getFiles().stream()
            .map(FileInventoryItemJSON::encodeO)
            .collect(Collectors.toCollection(JSONArray::new));
    out.put("files", files);

    JSONArray folders = input.getFolders().stream()
            .map(FolderInventoryItemJSON::encodeO)
            .collect(Collectors.toCollection(JSONArray::new));
    out.put("folders", folders);
    out.put("defaultEncryptionAlgorithm", input.getDefaultEncryption().toString());
    return out;
}
 
開發者ID:AstromechZA,項目名稱:bunkr,代碼行數:17,代碼來源:InventoryJSON.java

示例6: parseJsonContent

import org.json.simple.JSONAware; //導入依賴的package包/類
private void parseJsonContent( JSONAware jv, String entity, Map<String, RiskData> values ) {
	int hasTravis = 0;
	

	if( jv instanceof JSONArray ) {
		JSONArray ja = (JSONArray)jv;

		for (Object o : ja){

			JSONObject jo = (JSONObject)o;
			//System.out.println(jo.get("contributions"));
			String filename = jo.get("name").toString();
			if (filename.equals(".travis.yml")) {
				hasTravis = 1;
				break;
			}
		}
	}
	RiskData rd = new RiskData( GITHUB_PREFIX + "ci_link", entity, new Date(), RiskDataType.NUMBER, hasTravis );
	values.put( rd.getId(), rd );	
}
 
開發者ID:RISCOSS,項目名稱:riscoss-data-collector,代碼行數:22,代碼來源:RDCGithub.java

示例7: parseJsonParticipation

import org.json.simple.JSONAware; //導入依賴的package包/類
private void parseJsonParticipation(JSONAware jv, String entity, Map<String, RiskData> values) {
	if (jv instanceof JSONObject) {
		JSONObject jo = (JSONObject) jv;
		if (jo.containsKey("all")) {
			// JSONArray ja = (JSONArray)jo.get("all"));
			ArrayList<Long> ll = (ArrayList<Long>) jo.get("all");
			ArrayList<Double> doublelist = new ArrayList<Double>();
			Long sum = 0L;
			for (Long l : ll) {
				doublelist.add(l.doubleValue());
				sum += l;
			}

			Distribution d = new Distribution();
			d.setValues(doublelist);
			//weekly commit count for the repository owner and everyone else, 52 weeks
			RiskData rd = new RiskData(GITHUB_PREFIX + "participation", entity, new Date(),	RiskDataType.DISTRIBUTION, d);
			values.put(rd.getId(), rd);
			rd = new RiskData(GITHUB_PREFIX + "participation_sum", entity, new Date(), RiskDataType.NUMBER, sum);
			values.put(rd.getId(), rd);
		}
	}
}
 
開發者ID:RISCOSS,項目名稱:riscoss-data-collector,代碼行數:24,代碼來源:RDCGithub.java

示例8: decorate

import org.json.simple.JSONAware; //導入依賴的package包/類
/**
 * @see org.alfresco.repo.jscript.app.PropertyDecorator#decorate(QName, org.alfresco.service.cmr.repository.NodeRef, java.io.Serializable)
 */
@SuppressWarnings("unchecked")
public JSONAware decorate(QName propertyName, NodeRef nodeRef, Serializable value)
{
    String username = value.toString();
    String firstName = null;
    String lastName = null;
    JSONObject map = new JSONObject();
    map.put("userName", username);
    
    // DO NOT change this to just use getPersonOrNullImpl
    //  - there is Cloud THOR prod hack see personServiceImpl.personExists
    //  - and THOR-293 
    if (username.isEmpty())
    {
        firstName = "";
        lastName = "";
    }
    else if (this.personService.personExists(username))
    {
        NodeRef personRef = this.personService.getPerson(username, false);
        firstName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
        lastName = (String)this.nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
    }
    else if (username.equals("System") || username.startsWith("[email protected]"))
    {
        firstName = "System";
        lastName = "User";
    }
    else
    {
        map.put("isDeleted", true);
        return map;
    }
    
    map.put("firstName", firstName);
    map.put("lastName", lastName);
    map.put("displayName", ((firstName != null ? firstName + " " : "") + (lastName != null ? lastName : "")).replaceAll("^\\s+|\\s+$", ""));
    return map;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:43,代碼來源:UsernamePropertyDecorator.java

示例9: request

import org.json.simple.JSONAware; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public <T extends JSONAware> T request(String uri) throws IOException {
    Request.Response response = new Request(Cli.api + "/api" + uri).send();
    if (response.code() != 200) throw new IOException("Error " + response.code() + ": " + response.message());

    String json = response.text();
    if (json == null) return null;

    try { return (T) new JSONParser().parse(json); }
    catch (ParseException e) { throw new IOException(e); }
}
 
開發者ID:elodina,項目名稱:hdfs-mesos,代碼行數:12,代碼來源:HttpServerTest.java

示例10: encodeO

import org.json.simple.JSONAware; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static JSONAware encodeO(FragmentedRange fr)
{
    JSONArray ja = new JSONArray();
    for (int i : fr.toRepr())
    {
        ja.add(i);
    }
    return ja;
}
 
開發者ID:AstromechZA,項目名稱:bunkr,代碼行數:11,代碼來源:FragmentedRangeJSON.java

示例11: encodeO

import org.json.simple.JSONAware; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public static JSONAware encodeO(FileInventoryItem input)
{
    JSONObject out = new JSONObject();

    out.put(KEY_NAME, input.getName());
    out.put(KEY_UUID, input.getUuid().toString());
    out.put(KEY_BLOCKS, FragmentedRangeJSON.encodeO(input.getBlocks()));
    out.put(KEY_SIZE_ON_DISK, input.getSizeOnDisk());
    out.put(KEY_ACTUAL_SIZE, input.getActualSize());
    out.put(KEY_MODIFIED_AT, input.getModifiedAt());
    out.put(KEY_ENCRYPTION_ALGORITHM, input.getEncryptionAlgorithm().toString());

    if (input.getEncryptionData() != null)
        out.put(KEY_ENCRYPTION_DATA, DatatypeConverter.printBase64Binary(input.getEncryptionData()));
    else
        out.put(KEY_ENCRYPTION_DATA, null);

    if (input.getIntegrityHash() != null)
        out.put(KEY_INTEGRITY_HASH, DatatypeConverter.printBase64Binary(input.getIntegrityHash()));
    else
        out.put(KEY_INTEGRITY_HASH, null);

    out.put(KEY_MEDIA_TYPE, input.getMediaType());

    return out;
}
 
開發者ID:AstromechZA,項目名稱:bunkr,代碼行數:28,代碼來源:FileInventoryItemJSON.java

示例12: parseJsonContributors

import org.json.simple.JSONAware; //導入依賴的package包/類
private void parseJsonContributors( JSONAware jv, String entity, Map<String, RiskData> values ) {
	int contributions = 0;
	int contributors = 0;
	
	if( jv instanceof JSONArray ) {
		JSONArray ja = (JSONArray)jv;

		contributors = ja.size();
		//System.out.println("contributors: "+contributors);

		for (Object o : ja){
			JSONObject jo = (JSONObject)o;
			//System.out.println(jo.get("contributions"));
			contributions += Integer.parseInt(jo.get("contributions").toString());
		}
		
		getContribDistrib(ja, contributions, 99, entity, values);
		getContribDistrib(ja, contributions, 95, entity, values);
		getContribDistrib(ja, contributions, 90, entity, values);
		getContribDistrib(ja, contributions, 80, entity, values);
		getContribDistrib(ja, contributions, 50, entity, values);		

	}	

	//number of contributors (i.e. persons that did a commit)
	RiskData rd = new RiskData( GITHUB_PREFIX + "contributors", entity, new Date(), RiskDataType.NUMBER, contributors );
	values.put( rd.getId(), rd );
	//sum of all the commits done
	rd = new RiskData( GITHUB_PREFIX + "contributions_sum", entity, new Date(), RiskDataType.NUMBER, contributions );
	values.put( rd.getId(), rd );
	
	//commits per contributor
	if( contributors > 0 ) {
		rd = new RiskData( GITHUB_PREFIX + "commits_per_contributor", entity, new Date(), RiskDataType.NUMBER, contributions/contributors );
		values.put( rd.getId(), rd );
	}
}
 
開發者ID:RISCOSS,項目名稱:riscoss-data-collector,代碼行數:38,代碼來源:RDCGithub.java

示例13: ToJSONString

import org.json.simple.JSONAware; //導入依賴的package包/類
static public String ToJSONString(Object object)
{
    if(object instanceof JSONAware)
    {
        return ((JSONAware)object).toJSONString();
    }
    else
    {
        JSONArray array = new JSONArray();
        array.add(object);
        return array.toJSONString();
    }
}
 
開發者ID:StorageMonitor,項目名稱:StorageMonitor-Bukkit,代碼行數:14,代碼來源:HTTPResponse.java

示例14: makeSerializer

import org.json.simple.JSONAware; //導入依賴的package包/類
private static <T> InternalTranslater<T> makeSerializer(TypeAndAnnos info, SourJson sour) {

		Class<T> fromClass = (Class<T>) GenericTypeReflector.erase(info.type);

		SJTranslater<T> translater = sour.getTranslater(fromClass);
		if (translater != null)
			return new SJTranslaterTranslater<>(translater, info);

		if (	   JSONObject.class.isAssignableFrom(fromClass)   || JSONArray.class.isAssignableFrom(fromClass)
				|| Number.class.isAssignableFrom(fromClass)	      || Boolean.class.isAssignableFrom(fromClass)
				|| JSONAware.class.isAssignableFrom(fromClass)    || JSONStreamAware.class.isAssignableFrom(fromClass)
				|| String.class.isAssignableFrom(fromClass)	      || fromClass.isPrimitive()
				) {
			return new SelfTranslater<>(fromClass);
		}

		if (Collection.class.isAssignableFrom(fromClass))
			return new CollectionTranslater<>(info);

		if (fromClass.isArray())
			return new ArrayTranslater<>(info);

		if (Map.class.isAssignableFrom(fromClass))
			return new MapTranslater<>(info);

		if (fromClass.isEnum())
			return new EnumTranslater<>(info.type);

		if (SJUtils.isSystem(fromClass))
			return new StringTranslater<>(fromClass);

		if (!sour.isClassKnown(fromClass))
			throw new UnknownClassException(fromClass);

		return new ObjectTranslater<>(info.type);
	}
 
開發者ID:salomonbrys-deprecated,項目名稱:SourJSON,代碼行數:37,代碼來源:TranslaterCache.java

示例15: propertyToJSON

import org.json.simple.JSONAware; //導入依賴的package包/類
/**
 * Handles the work of converting values to JSON.
 * 
 * @param nodeRef NodeRef
 * @param propertyName QName
 * @param key String
 * @param value Serializable
 * @return the JSON value
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object propertyToJSON(final NodeRef nodeRef, final QName propertyName, final String key, final Serializable value)
{
	if (value != null)
    {
        // Has a decorator has been registered for this property?
        if (propertyDecorators.containsKey(propertyName))
        {
            JSONAware jsonAware = propertyDecorators.get(propertyName).decorate(propertyName, nodeRef, value);
            if (jsonAware != null)
            {
            	return jsonAware;
            }
        }
        else
        {
            // Built-in data type processing
            if (value instanceof Date)
            {
                JSONObject dateObj = new JSONObject();
                dateObj.put("value", JSONObject.escape(value.toString()));
                dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value)));
                return dateObj;
            }
            else if (value instanceof List)
            {
            	// Convert the List to a JSON list by recursively calling propertyToJSON
            	List<Object> jsonList = new ArrayList<Object>(((List<Serializable>) value).size());
            	for (Serializable listItem : (List<Serializable>) value)
            	{
            	    jsonList.add(propertyToJSON(nodeRef, propertyName, key, listItem));
            	}
            	return jsonList;
            }
            else if (value instanceof Double)
            {
                return (Double.isInfinite((Double)value) || Double.isNaN((Double)value) ? null : value.toString());
            }
            else if (value instanceof Float)
            {
                return (Float.isInfinite((Float)value) || Float.isNaN((Float)value) ? null : value.toString());
            }
            else
            {
            	return value.toString();
            }
        }
    }
	return null;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:60,代碼來源:JSONConversionComponent.java


注:本文中的org.json.simple.JSONAware類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。