本文整理了Java中com.eclipsesource.json.Json.object()
方法的一些代码示例,展示了Json.object()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.object()
方法的具体详情如下:
包路径:com.eclipsesource.json.Json
类名称:Json
方法名:object
[英]Creates a new empty JsonObject. This is equivalent to creating a new JsonObject using the constructor.
[中]创建一个新的空JsonObject。这相当于使用构造函数创建一个新的JsonObject。
代码示例来源:origin: Vedenin/useful-java-links
public static void main(String[] args) throws IOException {
// convert Java to writer
JsonObject root = Json.object().add("message", "Hi").add(
"place", Json.object().add("name", "World!")
);
StringWriter writer = new StringWriter();
root.writeTo(writer);
String json = writer.toString();
System.out.println(json);
System.out.println();
// convert writer to Java
JsonObject obj = Json.parse(json).asObject();
String message = obj.get("message").asString();
String name = obj.get("place").asObject().get("name").asString();
System.out.println(message + " " + name);
}
}
代码示例来源:origin: eclipse/leshan
@Override
public JsonObject jSerialize(X509Certificate certificate) {
final JsonObject o = Json.object();
// add pubkey info
o.add("pubkey", publicKeySerDes.jSerialize(certificate.getPublicKey()));
// Get certificate (DER encoding)
try {
o.add("b64Der", Base64.encodeBase64String(certificate.getEncoded()));
} catch (CertificateEncodingException e) {
throw new RuntimeException(e);
}
return o;
}
代码示例来源:origin: eclipse/leshan
@Override
public JsonObject jSerialize(X509Certificate certificate) {
final JsonObject o = Json.object();
// add pubkey info
o.add("pubkey", publicKeySerDes.jSerialize(certificate.getPublicKey()));
// Get certificate (DER encoding)
try {
o.add("b64Der", Base64.encodeBase64String(certificate.getEncoded()));
} catch (CertificateEncodingException e) {
throw new RuntimeException(e);
}
return o;
}
代码示例来源:origin: dernasherbrezon/r2cloud
@Override
public ModelAndView doGet(IHTTPSession session) {
ModelAndView result = new ModelAndView();
JsonObject entity = Json.object();
for (Entry<String, Result> cur : Metrics.HEALTH_REGISTRY.runHealthChecks().entrySet()) {
JsonObject value = Json.object().add("status", cur.getValue().getDetails().get("status").toString());
if (!cur.getValue().isHealthy()) {
value.add("message", cur.getValue().getMessage());
}
entity.add(cur.getKey(), value);
}
result.setData(entity.toString());
return result;
}
代码示例来源:origin: dernasherbrezon/r2cloud
public String toJson() {
JsonObject result = Json.object();
if (!isEmpty()) {
JsonObject errors = Json.object();
if (general != null) {
errors.add("general", general);
}
for (Entry<String, String> cur : entrySet()) {
errors.add(cur.getKey(), cur.getValue());
}
result.add("errors", errors);
}
return result.toString();
}
代码示例来源:origin: eclipse/leshan
private void sendError(String ticket, String message) {
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
JsonObject err = Json.object();
err.add("errorMessage", message);
m.add("err", err);
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: com.tcdng.unify/unify-core
public static String writeJsonObject(Object object) throws UnifyException {
try {
JsonObject jsonObject = Json.object();
DataUtils.writeJsonObject(object, jsonObject);
return jsonObject.toString();
} catch (UnifyException e) {
throw e;
} catch (Exception e) {
throw new UnifyException(UnifyCoreErrorConstants.DATAUTIL_ERROR, e);
}
}
代码示例来源:origin: org.eclipse.leshan/leshan-server-cluster
private void sendError(String ticket, String message) {
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
JsonObject err = Json.object();
err.add("errorMessage", message);
m.add("err", err);
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: fabienrenaud/java-json-benchmark
@Override
public com.eclipsesource.json.JsonValue minimaljson(Users obj) throws IOException {
com.eclipsesource.json.JsonObject jso = com.eclipsesource.json.Json.object();
if (obj.users != null) {
com.eclipsesource.json.JsonArray jsarr = (com.eclipsesource.json.JsonArray) com.eclipsesource.json.Json.array();
for (User u : obj.users) {
jsarr.add(minimaljson(u));
}
jso.add("users", jsarr);
}
return jso;
}
代码示例来源:origin: org.eclipse.leshan/leshan-server-cluster
private void sendAck(String ticket) {
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
m.add("ack", true);
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: eclipse/leshan
private void sendAck(String ticket) {
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
m.add("ack", true);
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: org.eclipse.leshan/leshan-server-cluster
public static byte[] serialize(Observation obs) {
JsonObject o = Json.object();
o.set("request", Hex.encodeHexString(serializer.serializeRequest(obs.getRequest()).bytes));
if (obs.getContext() != null)
o.set("peer", EndpointContextSerDes.serialize(obs.getContext()));
else
o.set("peer", EndpointContextSerDes.serialize(obs.getRequest().getDestinationContext()));
if (obs.getRequest().getUserContext() != null) {
JsonObject ctxObject = Json.object();
for (Entry<String, String> e : obs.getRequest().getUserContext().entrySet()) {
ctxObject.set(e.getKey(), e.getValue());
}
o.set("context", ctxObject);
}
return o.toString().getBytes();
}
代码示例来源:origin: eclipse/leshan
private void sendResponse(String ticket, LwM2mResponse response) {
if (response instanceof ObserveResponse) {
Observation observation = ((ObserveResponse) response).getObservation();
observatioIdToTicket.put(new KeyId(observation.getId()), ticket);
}
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
m.add("rep", ResponseSerDes.jSerialize(response));
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: org.eclipse.leshan/leshan-server-cluster
private void sendResponse(String ticket, LwM2mResponse response) {
if (response instanceof ObserveResponse) {
Observation observation = ((ObserveResponse) response).getObservation();
observatioIdToTicket.put(new KeyId(observation.getId()), ticket);
}
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
m.add("rep", ResponseSerDes.jSerialize(response));
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: eclipse/leshan
public static JsonObject serialize(Identity identity) {
JsonObject o = Json.object();
o.set(KEY_ADDRESS, identity.getPeerAddress().getHostString());
o.set(KEY_PORT, identity.getPeerAddress().getPort());
if (identity.isPSK()) {
o.set(KEY_ID, identity.getPskIdentity());
} else if (identity.isRPK()) {
PublicKey publicKey = identity.getRawPublicKey();
o.set(KEY_RPK, Hex.encodeHexString(publicKey.getEncoded()));
} else if (identity.isX509()) {
o.set(KEY_CN, identity.getX509CommonName());
}
return o;
}
代码示例来源:origin: org.eclipse.leshan/leshan-server-cluster
public static JsonObject serialize(Identity identity) {
JsonObject o = Json.object();
o.set(KEY_ADDRESS, identity.getPeerAddress().getHostString());
o.set(KEY_PORT, identity.getPeerAddress().getPort());
if (identity.isPSK()) {
o.set(KEY_ID, identity.getPskIdentity());
} else if (identity.isRPK()) {
PublicKey publicKey = identity.getRawPublicKey();
o.set(KEY_RPK, Hex.encodeHexString(publicKey.getEncoded()));
} else if (identity.isX509()) {
o.set(KEY_CN, identity.getX509CommonName());
}
return o;
}
代码示例来源:origin: eclipse/leshan
private void sendNotification(String ticket, LwM2mNode value) {
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
m.add("rep", ResponseSerDes.jSerialize(ObserveResponse.success(value)));
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: org.eclipse.leshan/leshan-server-cluster
private void sendNotification(String ticket, LwM2mNode value) {
try (Jedis j = pool.getResource()) {
JsonObject m = Json.object();
m.add("ticket", ticket);
m.add("rep", ResponseSerDes.jSerialize(ObserveResponse.success(value)));
j.publish(RESPONSE_CHANNEL, m.toString());
}
}
代码示例来源:origin: eclipse/leshan
@Override
public JsonObject jSerialize(ResourceModel m) {
final JsonObject o = Json.object();
o.add("id", m.id);
o.add("name", m.name);
o.add("operations", m.operations.toString());
o.add("instancetype", m.multiple ? "multiple" : "single");
o.add("mandatory", m.mandatory);
o.add("type", m.type.toString().toLowerCase());
o.add("range", m.rangeEnumeration);
o.add("units", m.units);
o.add("description", m.description);
return o;
}
代码示例来源:origin: dernasherbrezon/r2cloud
public static ModelAndView doLogin(Authenticator auth, String username, String password) {
String token = auth.authenticate(username, password);
ModelAndView result = new ModelAndView();
if (token == null) {
result.setData(new ValidationResult("Invalid login or password").toJson());
result.setStatus(Response.Status.UNAUTHORIZED);
} else {
JsonObject data = Json.object();
data.add("access_token", token);
data.add("token_type", "bearer");
data.add("expires_in", auth.getMaxAgeMillis() / 1000);
result.setData(data.toString());
}
return result;
}
内容来源于网络,如有侵权,请联系作者删除!