congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Json.fromJson
Code IndexAdd Tabnine 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)

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 testDeserializeEnumWithParser() {
 assertEquals(json.fromJson("{enumValue : \"FOO\"}", EnumInsideWithParser.class).enumValue,
      EnumInsideWithParser.Test.FOO);
}
origin: jclouds/legacy-jclouds

public void testDeserializeEnumWithParserAndBadValue() {
 assertEquals(json.fromJson("{enumValue : \"sd\"}", EnumInsideWithParser.class).enumValue,
      EnumInsideWithParser.Test.UNRECOGNIZED);
}
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

  • Updating database using SQL prepared statement
  • onRequestPermissionsResult (Fragment)
  • getResourceAsStream (ClassLoader)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now