本文整理了Java中org.jclouds.json.Json.toJson()
方法的一些代码示例,展示了Json.toJson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.toJson()
方法的具体详情如下:
包路径:org.jclouds.json.Json
类名称:Json
方法名:toJson
[英]Serialize the object into json. If the object is a generic type, use #toJson(Object,Type)
[中]将对象序列化为json。如果对象是泛型类型,则使用#toJson(对象,类型)
代码示例来源:origin: com.amysta.jclouds.api/oauth
@Override public String apply(Object input) {
String encodedHeader = String.format("{\"alg\":\"%s\",\"typ\":\"JWT\"}", alg);
String encodedClaimSet = json.toJson(input);
encodedHeader = base64Url().omitPadding().encode(encodedHeader.getBytes(UTF_8));
encodedClaimSet = base64Url().omitPadding().encode(encodedClaimSet.getBytes(UTF_8));
byte[] signature = alg.equals("none")
? null
: sha256(privateKey.get(), on(".").join(encodedHeader, encodedClaimSet).getBytes(UTF_8));
String encodedSignature = signature != null ? base64Url().omitPadding().encode(signature) : "";
// the final assertion in base 64 encoded {header}.{claimSet}.{signature} format
return on(".").join(encodedHeader, encodedClaimSet, encodedSignature);
}
代码示例来源:origin: org.apache.jclouds.api/oauth
@Override public String apply(Object input) {
String encodedHeader = String.format("{\"alg\":\"%s\",\"typ\":\"JWT\",\"x5t\":\"%s\"}", alg, certFingerprint.get().fingerprint());
String encodedClaimSet = json.toJson(input);
encodedHeader = base64Url().omitPadding().encode(encodedHeader.getBytes(UTF_8));
encodedClaimSet = base64Url().omitPadding().encode(encodedClaimSet.getBytes(UTF_8));
byte[] signature = alg.equals("none")
? null
: sha256(privateKey.get(), on(".").join(encodedHeader, encodedClaimSet).getBytes(UTF_8));
String encodedSignature = signature != null ? base64Url().omitPadding().encode(signature) : "";
// the final assertion in base 64 encoded {header}.{claimSet}.{signature} format
return on(".").join(encodedHeader, encodedClaimSet, encodedSignature);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testPropertiesSerializesDefaults() {
Properties props = new Properties();
props.put("string", "string");
props.put("number", "1");
props.put("boolean", "true");
assertEquals(json.toJson(props), "{\"string\":\"string\",\"boolean\":\"true\",\"number\":\"1\"}");
Properties props3 = new Properties(props);
assertEquals(json.toJson(props3), "{\"string\":\"string\",\"boolean\":\"true\",\"number\":\"1\"}");
Properties props2 = json.fromJson(json.toJson(props), Properties.class);
assertEquals(props2, props);
assertEquals(json.toJson(props2), json.toJson(props));
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testObjectNoDefaultConstructor() {
ObjectNoDefaultConstructor obj = new ObjectNoDefaultConstructor("foo", 1);
assertEquals(json.toJson(obj), "{\"stringValue\":\"foo\",\"intValue\":1}");
ObjectNoDefaultConstructor obj2 = json.fromJson(json.toJson(obj), ObjectNoDefaultConstructor.class);
assertEquals(obj2, obj);
assertEquals(json.toJson(obj2), json.toJson(obj));
}
代码示例来源:origin: org.apache.jclouds.api/rackspace-clouddns
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
checkArgument(checkNotNull(input, "input") instanceof Map, "This binder is only valid for Map<String, Record>");
checkNotNull(request, "request");
Map<String, Record> idsToRecords = (Map<String, Record>) input;
List<UpdateRecord> updateRecords = toUpdateRecordList(idsToRecords);
String json = jsonBinder.toJson(ImmutableMap.of("records", updateRecords));
request.setPayload(json);
request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON);
return request;
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testMapStringObjectWithBooleanKeysConvertToStrings() {
Map<String, Object> map = ImmutableMap.<String, Object> of("map", ImmutableMap.of(true, "value"));
assertEquals(json.toJson(map), "{\"map\":{\"true\":\"value\"}}");
Map<String, Object> map2 = json.fromJson(json.toJson(map), new TypeLiteral<Map<String, Object>>() {
}.getType());
// note conversion.. ensures valid
assertEquals(map2, ImmutableMap.<String, Object> of("map", ImmutableMap.of("true", "value")));
assertEquals(json.toJson(map2), json.toJson(map));
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testMapStringObjectWithNumericalKeysConvertToStrings() {
Map<String, Object> map = ImmutableMap.<String, Object> of("map", ImmutableMap.of(1, "value"));
assertEquals(json.toJson(map), "{\"map\":{\"1\":\"value\"}}");
Map<String, Object> map2 = json.fromJson(json.toJson(map), new TypeLiteral<Map<String, Object>>() {
}.getType());
// note conversion.. ensures valid
assertEquals(map2, ImmutableMap.<String, Object> of("map", ImmutableMap.of("1", "value")));
assertEquals(json.toJson(map2), json.toJson(map));
}
代码示例来源:origin: jclouds/legacy-jclouds
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
String json = jsonBinder.toJson(checkNotNull(payload, "payload"));
request.setPayload(json);
request.getPayload().getContentMetadata().setContentType("application/json");
return request;
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testExcluder() {
Json excluder = Guice.createInjector(new GsonModule(), new AbstractModule() {
protected void configure() {
bind(DefaultExclusionStrategy.class).to(ExcludeStringValue.class);
}
}).getInstance(Json.class);
ObjectNoDefaultConstructor obj = new ObjectNoDefaultConstructor("foo", 1);
assertEquals(excluder.toJson(obj), "{\"intValue\":1}");
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testByteList() {
ByteList bl = new ByteList();
bl.checksum = asList(base16().lowerCase().decode("1dda05ed139664f1f89b9dec482b77c0"));
assertEquals(json.toJson(bl), "{\"checksum\":\"1dda05ed139664f1f89b9dec482b77c0\"}");
assertEquals(json.fromJson(json.toJson(bl), ByteList.class).checksum, bl.checksum);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testList() {
String json = "{\"list\":[8431,8433]}";
// gson deserialized numbers to double, so integers end up changed to fractions
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()),
ImmutableMap.<String, Object> of("list", ImmutableList.of(8431d, 8433d)));
assertEquals(mapper.toJson(ImmutableMap.<String, Object> of("list", ImmutableList.of(8431, 8433))), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testHash() {
String json = "{\"tomcat6\":{\"ssl_port\":8433}}";
// gson deserialized numbers to double, so integers end up changed to fractions
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()),
ImmutableMap.<String, Object> of("tomcat6", ImmutableMap.of("ssl_port", 8433d)));
assertEquals(mapper.toJson(ImmutableMap.<String, Object> of("tomcat6", ImmutableMap.of("ssl_port", 8433))), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testNumber() {
String json = "{\"number\":1.0}";
Map<String, Object> map = ImmutableMap.<String, Object> of("number", 1d);
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testString() {
String json = "{\"name\":\"fooy\"}";
Map<String, Object> map = ImmutableMap.<String, Object> of("name", "fooy");
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testObject() {
String json = "{\"tomcat6\":{\"ssl_port\":8433}}";
Map<String, JsonBall> map = ImmutableMap.<String, JsonBall> of("tomcat6", new JsonBall("{\"ssl_port\":8433}"));
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testBoolean() {
String json = "{\"boolean\":false}";
Map<String, JsonBall> map = ImmutableMap.<String, JsonBall> of("boolean", new JsonBall(false));
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testList() {
String json = "{\"list\":[8431,8433]}";
Map<String, JsonBall> map = ImmutableMap.<String, JsonBall> of("list", new JsonBall("[8431,8433]"));
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testNumber() {
String json = "{\"number\":1.0}";
Map<String, JsonBall> map = ImmutableMap.<String, JsonBall> of("number", new JsonBall(1.0));
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testString() {
String json = "{\"name\":\"fooy\"}";
Map<String, JsonBall> map = ImmutableMap.<String, JsonBall> of("name", new JsonBall("fooy"));
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), map);
assertEquals(mapper.toJson(map), json);
}
代码示例来源:origin: jclouds/legacy-jclouds
public void testProvidedMapWithValue() throws IOException {
Map<String, InputStream> map = new CopyInputStreamInputSupplierMap(
new ConcurrentHashMap<String, InputSupplier<InputStream>>());
map.put("test", new ByteArrayInputStream(json.toJson(new Credentials("user", "pass")).getBytes()));
checkConsistent(map, getStore(createInjectorWithProvidedMap(map)), "test", new Credentials("user", "pass"));
checkConsistent(map, getStore(createInjectorWithProvidedMap(map)), "test", new Credentials("user", "pass"));
remove(map, getStore(createInjectorWithProvidedMap(map)), "test");
}
内容来源于网络,如有侵权,请联系作者删除!