本文整理匯總了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;
}
示例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;
}
示例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;
});
}
示例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;
}
示例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;
}
示例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 );
}
示例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);
}
}
}
示例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;
}
示例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); }
}
示例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;
}
示例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;
}
示例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 );
}
}
示例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();
}
}
示例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);
}
示例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;
}