org.apache.shindig.common.JsonSerializer类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中org.apache.shindig.common.JsonSerializer类的一些代码示例,展示了JsonSerializer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonSerializer类的具体详情如下:
包路径:org.apache.shindig.common.JsonSerializer
类名称:JsonSerializer

JsonSerializer介绍

[英]Serializes a JSONObject. The methods here are designed to be substantially more CPU and memory efficient than those found in org.json or net.sf.json. In profiling, the performance of both of these libraries has been found to be woefully inadequate for large scale deployments. The append*() methods can be used to serialize directly into an Appendable, such as an output stream. This avoids unnecessary copies to intermediate objects. To reduce output size, null values in json arrays and objects will always be removed.
[中]序列化JSONObject。这里的方法被设计为比org中的方法具有更高的CPU和内存效率。json或net。旧金山。json。在概要分析中,发现这两个库的性能对于大规模部署来说都远远不够。append*()方法可用于直接序列化为可追加文件,例如输出流。这样可以避免不必要的复制到中间对象。为了减少输出大小,json数组和对象中的空值将始终被删除。

代码示例

代码示例来源:origin: apache/shindig

/**
 * Convert the passed in object to a string.
 *
 * @param pojo The object to convert
 * @return An object whose toString method will return json
 */
public String convertToString(final Object pojo) {
 return JsonSerializer.serialize(pojo);
}

代码示例来源:origin: com.lmco.shindig/shindig-common

value.getClass().isEnum()) {
 appendString(buf, value.toString());
} else if (value instanceof Date) {
 appendString(buf, DateUtil.formatIso8601Date((Date)value));
} else if (value instanceof JSONObject) {
 appendJsonObject(buf, (JSONObject) value);
} else if (value instanceof JSONArray) {
 appendJsonArray(buf, (JSONArray) value);
} else if (value instanceof Map) {
 appendMap(buf, (Map<String, Object>) value);
} else if (value instanceof Multimap) {
 appendMultimap(buf, (Multimap<String, Object>) value);
} else if (value instanceof Collection) {
 appendCollection(buf, (Collection<Object>) value);
} else if (value.getClass().isArray()) {
 appendArray(buf, (Object[]) value);
} else {
 appendPojo(buf, value);

代码示例来源:origin: org.gatein.shindig/shindig-common

public void append(Appendable buf, Object pojo) throws IOException {
 JsonSerializer.append(buf, pojo);
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

private void injectTemplateLibrary(TemplateLibrary library, Element head) {
 try {
  String libraryContent = library.serialize();
  if (Strings.isNullOrEmpty(libraryContent)) {
   return;
  }
  Element scriptElement = head.getOwnerDocument().createElement("script");
  scriptElement.setAttribute("type", "text/javascript");
  StringBuilder buffer = new StringBuilder();
  buffer.append("opensocial.template.Loader.loadContent(");
  JsonSerializer.appendString(buffer, library.serialize());
  buffer.append(',');
  JsonSerializer.appendString(buffer, library.getLibraryUri().toString());
  buffer.append(");");
  scriptElement.setTextContent(buffer.toString());
  head.appendChild(scriptElement);
 } catch (IOException ioe) {
  // This should never happen.
 }
}

代码示例来源:origin: org.apache.shindig/shindig-gadgets

/**
 * Generate the correctly parameterized Javascript call to swfobject
 */
String buildSwfObjectCall(SwfObjectConfig config, String altContentId) {
 try {
  StringBuilder builder = new StringBuilder();
  builder.append("swfobject.embedSWF(");
  JsonSerializer.appendString(builder, config.swf.toString());
  builder.append(",\"");
  builder.append(altContentId);
  builder.append("\",");
  JsonSerializer.appendString(builder, config.width);
  builder.append(',');
  JsonSerializer.appendString(builder, config.height);
  builder.append(",\"").append(flashMinVersion).append("\",");
  builder.append("null,null,");
  JsonSerializer.appendMap(builder, config.getParams());
  builder.append(',');
  JsonSerializer.appendMap(builder, config.getAttributes());
  builder.append(");");
  return builder.toString();
 } catch (IOException ioe) {
  // Should not happen
  throw new RuntimeException(ioe);
 }
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Appends a Map to the buffer.
 *
 * @throws IOException If {@link Appendable#append(char)} throws an exception.
 */
public static void appendMap(final Appendable buf, final Map<String, ?> map) throws IOException {
 buf.append('{');
 boolean firstDone = false;
 for (Map.Entry<String, ?> entry : map.entrySet()) {
  Object value = entry.getValue();
  if (value != null) {
   if (firstDone) {
    buf.append(',');
   } else {
    firstDone = true;
   }
   Object key = entry.getKey();
   appendString(buf, key.toString());
   buf.append(':');
   append(buf, value);
  }
 }
 buf.append('}');
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Appends a Map to the buffer.
 *
 * @throws IOException If {@link Appendable#append(char)} throws an exception.
 */
public static void appendMultimap(Appendable buf, Multimap<String, Object> map) throws IOException {
 appendMap(buf, map.asMap());
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Serializes a Collection as a JSON array. Does not guard against cyclical references.
 */
public static String serialize(Collection<?> collection) {
 StringBuilder buf = new StringBuilder(collection.size() * BASE_MULTIPLIER);
 try {
  appendCollection(buf, collection);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: apache/shindig

/**
 * Serializes an array as a JSON array. Does not guard against cyclical references
 */
public static String serialize(Object[] array) {
 StringBuilder buf = new StringBuilder(array.length * BASE_MULTIPLIER);
 try {
  appendArray(buf, array);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: apache/shindig

/**
 * Serializes a JSON array. Does not guard against cyclical references
 */
public static String serialize(JSONArray array) {
 StringBuilder buf = new StringBuilder(array.length() * BASE_MULTIPLIER);
 try {
  appendJsonArray(buf, array);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Serialize a JSONObject. Does not guard against cyclical references.
 */
public static String serialize(JSONObject object) {
 StringBuilder buf = new StringBuilder(object.length() * BASE_MULTIPLIER);
 try {
  appendJsonObject(buf, object);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: org.gatein.shindig/shindig-gadgets

private void injectTemplateLibrary(TemplateLibrary library, Element head) {
 try {
  String libraryContent = library.serialize();
  if (StringUtils.isEmpty(libraryContent)) {
   return;
  }
  
  Element scriptElement = head.getOwnerDocument().createElement("script");
  scriptElement.setAttribute("type", "text/javascript");
  StringBuilder buffer = new StringBuilder();
  buffer.append("opensocial.template.Loader.loadContent(");
  JsonSerializer.appendString(buffer, library.serialize());
  buffer.append(',');
  JsonSerializer.appendString(buffer, library.getLibraryUri().toString());
  buffer.append(");");       
  scriptElement.setTextContent(buffer.toString());
  head.appendChild(scriptElement);
 } catch (IOException ioe) {
  // This should never happen.
 }
}

代码示例来源:origin: com.lmco.shindig/shindig-gadgets

/**
 * Generate the correctly parameterized Javascript call to swfobject
 */
String buildSwfObjectCall(SwfObjectConfig config, String altContentId) {
 try {
  StringBuilder builder = new StringBuilder();
  builder.append("swfobject.embedSWF(");
  JsonSerializer.appendString(builder, config.swf.toString());
  builder.append(",\"");
  builder.append(altContentId);
  builder.append("\",");
  JsonSerializer.appendString(builder, config.width);
  builder.append(',');
  JsonSerializer.appendString(builder, config.height);
  builder.append(",\"").append(flashMinVersion).append("\",");
  builder.append("null,null,");
  JsonSerializer.appendMap(builder, config.getParams());
  builder.append(',');
  JsonSerializer.appendMap(builder, config.getAttributes());
  builder.append(");");
  return builder.toString();
 } catch (IOException ioe) {
  // Should not happen
  throw new RuntimeException(ioe);
 }
}

代码示例来源:origin: org.gatein.shindig/shindig-common

/**
 * Appends a Map to the buffer.
 *
 * @throws IOException If {@link Appendable#append(char)} throws an exception.
 */
public static void appendMap(final Appendable buf, final Map<String, ?> map) throws IOException {
 buf.append('{');
 boolean firstDone = false;
 for (Map.Entry<String, ?> entry : map.entrySet()) {
  Object value = entry.getValue();
  if (value != null) {
   if (firstDone) {
    buf.append(',');
   } else {
    firstDone = true;
   }
   Object key = entry.getKey();
   appendString(buf, key.toString());
   buf.append(':');
   append(buf, value);
  }
 }
 buf.append('}');
}

代码示例来源:origin: org.gatein.shindig/shindig-common

/**
 * Appends a Map to the buffer.
 *
 * @throws IOException If {@link Appendable#append(char)} throws an exception.
 */
public static void appendMultimap(Appendable buf, Multimap<String, Object> map) throws IOException {
 appendMap(buf, map.asMap());
}

代码示例来源:origin: com.lmco.shindig/shindig-common

/**
 * Serializes a Collection as a JSON array. Does not guard against cyclical references.
 */
public static String serialize(Collection<?> collection) {
 StringBuilder buf = new StringBuilder(collection.size() * BASE_MULTIPLIER);
 try {
  appendCollection(buf, collection);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Serializes an array as a JSON array. Does not guard against cyclical references
 */
public static String serialize(Object[] array) {
 StringBuilder buf = new StringBuilder(array.length * BASE_MULTIPLIER);
 try {
  appendArray(buf, array);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: org.apache.shindig/shindig-common

/**
 * Serializes a JSON array. Does not guard against cyclical references
 */
public static String serialize(JSONArray array) {
 StringBuilder buf = new StringBuilder(array.length() * BASE_MULTIPLIER);
 try {
  appendJsonArray(buf, array);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: org.gatein.shindig/shindig-common

/**
 * Serialize a JSONObject. Does not guard against cyclical references.
 */
public static String serialize(JSONObject object) {
 StringBuilder buf = new StringBuilder(object.length() * BASE_MULTIPLIER);
 try {
  appendJsonObject(buf, object);
 } catch (IOException e) {
  // Shouldn't ever happen unless someone adds something to append*.
  throw new RuntimeException(e);
 }
 return buf.toString();
}

代码示例来源:origin: org.apache.shindig/shindig-common

value.getClass().isEnum()) {
 appendString(buf, value.toString());
} else if (value instanceof Date) {
 appendString(buf, DateUtil.formatIso8601Date((Date)value));
} else if (value instanceof JSONObject) {
 appendJsonObject(buf, (JSONObject) value);
} else if (value instanceof JSONArray) {
 appendJsonArray(buf, (JSONArray) value);
} else if (value instanceof Map) {
 appendMap(buf, (Map<String, Object>) value);
} else if (value instanceof Multimap) {
 appendMultimap(buf, (Multimap<String, Object>) value);
} else if (value instanceof Collection) {
 appendCollection(buf, (Collection<Object>) value);
} else if (value.getClass().isArray()) {
 appendArray(buf, (Object[]) value);
} else {
 appendPojo(buf, value);

相关文章