Codota Logo
Json.fromJson
Code IndexAdd Codota to your IDE (free)

How to use
fromJson
method
in
org.jclouds.json.Json

Best Java code snippets using org.jclouds.json.Json.fromJson (Showing top 20 results out of 342)

  • Common ways to obtain Json
private void myMethod () {
Json j =
  • Codota IconInjector injector;injector.getInstance(Json.class)
  • Smart code suggestions by Codota
}
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: 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: jclouds/legacy-jclouds

  @SuppressWarnings("unchecked")
  public <V> V apply(InputStream stream, Type type) throws IOException {
   try {
     return (V) json.fromJson(Strings2.toStringAndClose(stream), type);
   } finally {
     if (stream != null)
      stream.close();
   }
  }
}
origin: jclouds/legacy-jclouds

@Provides
@Singleton
public Map<OsFamily, Map<String, String>> provideOsVersionMap(ComputeServiceConstants.ReferenceData data, Json json) {
 return json.fromJson(data.osVersionMapJson, new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
 }.getType());
}
origin: apache/jclouds

@Provides
@Singleton
public final Map<OsFamily, Map<String, String>> provideOsVersionMap(ComputeServiceConstants.ReferenceData data, Json json) {
 return json.fromJson(data.osVersionMapJson, new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
 }.getType());
}
origin: io.cloudsoft.jclouds/jclouds-core

  @SuppressWarnings("unchecked")
  public <V> V apply(InputStream stream, Type type) throws IOException {
   try {
     return (V) json.fromJson(Strings2.toStringAndClose(stream), type);
   } finally {
     if (stream != null)
      stream.close();
   }
  }
}
origin: org.jclouds/jclouds-core

  @SuppressWarnings("unchecked")
  public <V> V apply(InputStream stream, Type type) throws IOException {
   try {
     return (V) json.fromJson(Strings2.toStringAndClose(stream), type);
   } finally {
     if (stream != null)
      stream.close();
   }
  }
}
origin: org.apache.jclouds/jclouds-compute

@Provides
@Singleton
public final Map<OsFamily, Map<String, String>> provideOsVersionMap(ComputeServiceConstants.ReferenceData data, Json json) {
 return json.fromJson(data.osVersionMapJson, new TypeLiteral<Map<OsFamily, Map<String, String>>>() {
 }.getType());
}
origin: org.apache.jclouds.provider/google-compute-engine

  @Override
  public Map<String, Object> apply(String input) {
   try {
     return json.fromJson(input, new TypeLiteral<Map<String, Object>>() {
     }.getType());
   } catch (Exception ex) {
     return null;
   }
  }
};
origin: org.jclouds.api/chef

@Override
public List<String> apply(String from) {
 DatabagItem bootstrapConfig = bootstrapConfigForGroup.apply(from);
 Map<String, JsonBall> config = json.fromJson(bootstrapConfig.toString(),
    BootstrapConfigForGroup.BOOTSTRAP_CONFIG_TYPE);
 JsonBall runlist = config.get("run_list");
 return json.fromJson(runlist.toString(), RUN_LIST_TYPE);
}
origin: jclouds/legacy-jclouds

public void testDeserializeEnumWithParserAndBadValue() {
 assertEquals(json.fromJson("{enumValue : \"sd\"}", EnumInsideWithParser.class).enumValue,
      EnumInsideWithParser.Test.UNRECOGNIZED);
}
origin: jclouds/legacy-jclouds

public void testDeserializeEnumWithParser() {
 assertEquals(json.fromJson("{enumValue : \"FOO\"}", EnumInsideWithParser.class).enumValue,
      EnumInsideWithParser.Test.FOO);
}
origin: com.amysta.jclouds/jclouds-core

 @Override public Credentials apply(ByteSource from) {
   try {
    String creds = (checkNotNull(from)).asCharSource(Charsets.UTF_8).read();
    return json.fromJson(creds, Credentials.class);
   } catch (Exception e) {
    logger.warn(e, "ignoring problem retrieving credentials");
    return null;
   }
 }
}
origin: apache/jclouds

public void autoValueSerializedNames() {
 Json json = Guice.createInjector(new GsonModule()).getInstance(Json.class);
 SerializedNamesType resource = SerializedNamesType.create("1234", Collections.<String, String>emptyMap());
 String spinalJson = "{\"Id\":\"1234\",\"Volumes\":{}}";
 assertEquals(json.toJson(resource), spinalJson);
 assertEquals(json.fromJson(spinalJson, SerializedNamesType.class), resource);
}
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

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 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

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 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));
}
org.jclouds.jsonJsonfromJson

Javadoc

Deserialize the object from json. If the object is a generic type, use #fromJson(Object,Type)

Popular methods of Json

  • toJson
    Serialize the generic object into json. If the object is not a generic, use #toJson(Object,Type)
  • <init>
  • setIgnoreUnknownFields
  • setOutputType
  • setTypeName
  • setUsePrototypes

Popular in Java

  • Creating JSON documents from java classes using gson
  • setScale (BigDecimal)
  • getSupportFragmentManager (FragmentActivity)
    Return the FragmentManager for interacting with fragments associated with this activity.
  • setRequestProperty (URLConnection)
    Sets the general request property. If a property with the key already exists, overwrite its value wi
  • InputStreamReader (java.io)
    An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • BitSet (java.util)
    This class implements a vector of bits that grows as needed. Each component of the bit set has a boo
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now