本文整理了Java中org.jclouds.json.Json
类的一些代码示例,展示了Json
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json
类的具体详情如下:
包路径:org.jclouds.json.Json
类名称:Json
暂无
代码示例来源:origin: stackoverflow.com
Json json = new Json();
json.setTypeName(null);
json.setUsePrototypes(false);
json.setIgnoreUnknownFields(true);
json.setOutputType(OutputType.json);
// I'm using your file as a String here, but you can supply the file as well
Data data = json.fromJson(Data.class, "{\"table\": [{\"id\": 1},{\"id\": 2},{\"id\": 3},{\"id\": 4}]}");
代码示例来源: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 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: org.jclouds.api/rackspace-clouddns
private String toJSON(Iterable<UpdateRecord> records, URI deviceURI, String serviceName) {
return jsonBinder.toJson(ImmutableMap.<String, Object> of(
"recordsList", ImmutableMap.of("records", records),
"link", ImmutableMap.<String, Object> of(
"href", deviceURI,
"rel", serviceName)));
}
代码示例来源:origin: jclouds/legacy-jclouds
@SuppressWarnings("unchecked")
@Override
public <R extends HttpRequest> R bindToRequest(R request, Object arg) {
CreateRecord<?> in = CreateRecord.class.cast(checkNotNull(arg, "record to create"));
URI path = uriBuilder(request.getEndpoint())
.build(ImmutableMap.<String, Object> builder()
.put("type", in.getType())
.put("fqdn", in.getFQDN()).build());
return (R) request.toBuilder()
.endpoint(path)
.payload(json.toJson(ImmutableMap.of("rdata", in.getRData(), "ttl", in.getTTL()))).build();
}
}
代码示例来源:origin: apache/jclouds
public void testContainerWithVolumesNull() {
Container container = json.fromJson("{ \"Id\": \"foo\", \"Volumes\": null }", Container.class);
assertNotNull(container);
assertEquals(container.id(), "foo");
assertEquals(container.volumes(), ImmutableMap.of());
}
代码示例来源:origin: jclouds/legacy-jclouds-chef
public void test1() {
String json = "{\"my_key\":\"my_data\",\"id\":\"item1\"}";
DatabagItem item = new DatabagItem("item1", json);
assertEquals(handler.apply(HttpResponse.builder().statusCode(200).message("ok").payload(json).build()), item);
assertEquals(mapper.toJson(item), json);
}
}
代码示例来源: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: 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 testDeserializeEnumWithParser() {
assertEquals(json.fromJson("{enumValue : \"FOO\"}", EnumInsideWithParser.class).enumValue,
EnumInsideWithParser.Test.FOO);
}
代码示例来源:origin: org.apache.jclouds.labs/openstack-glance
.method("GET").endpoint(baseEndpointUri)
.addHeader(VERSION_NEGOTIATION_HEADER, "true").build();
InputStream response = client.invoke(negotiationRequest).getPayload().openStream();
VersionsJsonResponse versions = json.fromJson(Strings2.toStringAndClose(response), VersionsJsonResponse.class);
for (VersionsJsonResponse.Version version : versions.versions) {
if (apiVersion.equals(version.id)) {
代码示例来源:origin: com.amysta.jclouds/jclouds-core
@SuppressWarnings("unchecked")
public <V> V apply(InputStream stream, Type type) throws IOException {
try {
return (V) json.fromJson(stream, type);
} finally {
if (stream != null)
stream.close();
}
}
}
代码示例来源:origin: stackoverflow.com
Hashtable<String, String> hashTable = new Hashtable<String, String>();
Json json = new Json();
hashTable.put("test", json.toJson(ints) ); //here you are serializing the array
... //putting the map into preferences
String serializedInts = Gdx.app.getPreferences("preferences").getString("test");
int[] deserializedInts = json.fromJson(int[].class, serializedInts); //you need to pass the class type - be aware of it!
代码示例来源:origin: stackoverflow.com
Json json = new Json();
ArrayList<HexTile> hexTiles = json.fromJson(ArrayList.class, Gdx.files.internal("myJsonFile.json"));
代码示例来源: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: stackoverflow.com
PlayerScore score = new PlayerScore("Player1", 1537443); // The Highscore of the Player1
Json json = new Json();
String score = json.toJson(score);
代码示例来源:origin: stackoverflow.com
Json json = new Json();
json.setTypeName(null);
json.setUsePrototypes(false);
json.setIgnoreUnknownFields(true);
json.setOutputType(OutputType.json);
json.toJson(config, GameConfig.class);
代码示例来源: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 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: org.jclouds.api/rackspace-clouddns
private String toJSON(Iterable<Record> records, URI deviceURI, String serviceName) {
return jsonBinder.toJson(ImmutableMap.<String, Object> of(
"recordsList", ImmutableMap.of("records", records),
"link", ImmutableMap.<String, Object> of(
"href", deviceURI,
"rel", serviceName)));
}
内容来源于网络,如有侵权,请联系作者删除!