本文整理了Java中elemental.json.Json
类的一些代码示例,展示了Json
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json
类的具体详情如下:
包路径:elemental.json.Json
类名称:Json
[英]Vends out implementation of JsonFactory.
[中]出售JsonFactory的实现。
代码示例来源:origin: com.vaadin/vaadin-server
/**
* Creates the JsonObject for given data object. This method calls all data
* generators for it.
*
* @param data
* data object to be made into a json object
* @return json object representing the data object
*/
protected JsonObject getDataObject(T data) {
JsonObject dataObject = Json.createObject();
for (DataGenerator<T> generator : generators) {
generator.generateData(data, dataObject);
}
return dataObject;
}
代码示例来源:origin: com.vaadin/vaadin-server
private static JsonArray encodeArrayContents(Type componentType,
Object array, ConnectorTracker connectorTracker) {
JsonArray jsonArray = Json.createArray();
for (int i = 0; i < Array.getLength(array); i++) {
EncodeResult encodeResult = encode(Array.get(array, i), null,
componentType, connectorTracker);
jsonArray.set(i, encodeResult.getEncodedValue());
}
return jsonArray;
}
代码示例来源:origin: com.vaadin/vaadin-server
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
// Read String versions of JsonObjects and parse into JsonObjects as
// JsonObject is not serializable
diffStates = new HashMap<>();
@SuppressWarnings("unchecked")
Map<ClientConnector, String> stringDiffStates = (HashMap<ClientConnector, String>) in
.readObject();
diffStates = new HashMap<>(stringDiffStates.size() * 2);
for (ClientConnector key : stringDiffStates.keySet()) {
try {
diffStates.put(key, Json.parse(stringDiffStates.get(key)));
} catch (JsonException e) {
throw new IOException(e);
}
}
}
代码示例来源:origin: com.vaadin/vaadin-server
private JsonArray toJsonArray(List<Dependency> list) {
JsonArray result = Json.createArray();
for (int i = 0; i < list.size(); i++) {
JsonObject dep = Json.createObject();
Dependency dependency = list.get(i);
dep.put("type", dependency.getType().name());
dep.put("url", dependency.getUrl());
result.set(i, dep);
}
return result;
}
代码示例来源:origin: com.haulmont.cuba/cuba-web-widgets
private JsonObject getJsonObject(T suggestion) {
final JsonObject object = Json.createObject();
//noinspection unchecked
object.put(SUGGESTION_ID, Json.create(keyMapper.key(suggestion)));
String caption = textViewConverter.apply(suggestion);
object.put(SUGGESTION_CAPTION, Json.create(caption));
if (optionsStyleProvider != null) {
String styleName = optionsStyleProvider.apply(suggestion);
object.put(SUGGESTION_STYLE_NAME, Json.create(styleName));
}
return object;
}
代码示例来源:origin: com.vaadin/vaadin-testbench-core
private JsonValue createJsonValue(Object value) {
if (value == null) {
return Json.createNull();
} else if (value instanceof String) {
return Json.create((String) value);
} else if (value instanceof Number) {
return Json.create(((Number) value).doubleValue());
} else if (value instanceof Boolean) {
return Json.create((Boolean) value);
} else {
throw new IllegalArgumentException(
"Type of property is unsupported: "
+ value.getClass().getName());
}
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public JsonValue serialize(Date value, ConnectorTracker connectorTracker) {
return Json.create(value.getTime());
}
代码示例来源:origin: jreznot/electron-java-app
private void callElectronUiApi(String[] args) {
JsonArray paramsArray = Json.createArray();
int i = 0;
for (String arg : args) {
paramsArray.set(i, Json.create(arg));
i++;
}
getPage().getJavaScript().execute("callElectronUiApi(" + paramsArray.toJson() + ")");
}
代码示例来源:origin: com.vaadin/flow-server
return Json.createNull();
JsonObject json = Json.createObject();
BeanInfo info = Introspector.getBeanInfo(bean.getClass());
for (PropertyDescriptor pd : info.getPropertyDescriptors()) {
代码示例来源:origin: com.vaadin/vaadin-server
private void putValueOrNull(JsonObject object, String key, String value) {
assert object != null;
assert key != null;
if (value == null) {
object.put(key, Json.createNull());
} else {
object.put(key, value);
}
}
}
代码示例来源:origin: org.eclipse.che.core/che-core-ide-app
@Provides
@Singleton
protected JsonFactory provideJsonFactory() {
return Json.instance();
}
}
代码示例来源:origin: com.vaadin/vaadin-server
public String asJson() {
JsonArray uris = Json.createArray();
for (String uri : sourceUris) {
uris.set(uris.length(), uri);
}
JsonObject object = Json.createObject();
object.put("version", Version.getFullVersion());
object.put("timestamp", Long.toString(timestamp));
object.put("uris", uris);
object.put("css", css);
return object.toJson();
}
代码示例来源:origin: com.vaadin/flow-server
/**
* Helper for encoding any "primitive" value that is directly supported in
* JSON. Supported values types are {@link String}, {@link Number},
* {@link Boolean}, {@link JsonValue}. <code>null</code> is also supported.
*
* @param value
* the value to encode
* @return the value encoded as JSON
*/
public static JsonValue encodeWithoutTypeInfo(Object value) {
if (value == null) {
return Json.createNull();
}
Class<?> type = value.getClass();
if (String.class.equals(value.getClass())) {
return Json.create((String) value);
} else if (Integer.class.equals(type) || Double.class.equals(type)) {
return Json.create(((Number) value).doubleValue());
} else if (Boolean.class.equals(type)) {
return Json.create(((Boolean) value).booleanValue());
} else if (JsonValue.class.isAssignableFrom(type)) {
return (JsonValue) value;
}
assert !canEncodeWithoutTypeInfo(type);
throw new IllegalArgumentException(
"Can't encode " + value.getClass() + " to json");
}
代码示例来源:origin: com.vaadin/vaadin-server
@Override
public JsonValue encode(Object value) {
if (value == null) {
return super.encode(null);
} else {
return Json.create(value.toString());
}
}
代码示例来源:origin: com.vaadin/vaadin-server
private static void putValueOrJsonNull(JsonObject json, String key,
String value) {
if (value == null) {
json.put(key, Json.createNull());
} else {
json.put(key, value);
}
}
代码示例来源:origin: com.googlecode.gwtquery/gwtquery
public static JsonObject parse(String jsonString) {
return instance().parse(jsonString);
}
}
代码示例来源:origin: com.vaadin/vaadin-server
private static JsonObject encodeStringMap(Type valueType, Map<?, ?> map,
ConnectorTracker connectorTracker) {
JsonObject jsonMap = Json.createObject();
for (Entry<?, ?> entry : map.entrySet()) {
String key = (String) entry.getKey();
EncodeResult encodedValue = encode(entry.getValue(), null,
valueType, connectorTracker);
jsonMap.put(key, encodedValue.getEncodedValue());
}
return jsonMap;
}
代码示例来源:origin: com.vaadin/vaadin-server
private static JsonArray encodeCollection(Type targetType,
Collection<?> collection, ConnectorTracker connectorTracker) {
JsonArray jsonArray = Json.createArray();
for (Object o : collection) {
jsonArray.set(jsonArray.length(),
encodeChild(targetType, 0, o, connectorTracker));
}
return jsonArray;
}
代码示例来源:origin: com.vaadin/vaadin-server
.getConnectorTracker().getDirtyVisibleConnectors();
JsonObject hierarchyInfo = Json.createObject();
for (ClientConnector connector : dirtyVisibleConnectors) {
String connectorId = connector.getConnectorId();
JsonArray children = Json.createArray();
代码示例来源:origin: com.vaadin/vaadin-server
private ScssCacheEntry loadPersistedScssCache(String scssFilename,
ServletContext sc) throws IOException {
String realFilename = sc.getRealPath(scssFilename);
File scssCacheFile = getScssCacheFile(new File(realFilename));
if (!scssCacheFile.exists()) {
return null;
}
String jsonString = readFile(scssCacheFile, StandardCharsets.UTF_8);
JsonObject entryJson = Json.parse(jsonString);
String cacheVersion = entryJson.getString("version");
if (!Version.getFullVersion().equals(cacheVersion)) {
// Compiled for some other Vaadin version, discard cache
scssCacheFile.delete();
return null;
}
return new ScssCacheEntry(entryJson);
}
内容来源于网络,如有侵权,请联系作者删除!