当前位置: 首页>>代码示例>>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;未经允许,请勿转载。