org.eclipse.wst.jsdt.js.node.common.util

## Class JsonUtil

- java.lang.Object
- - org.eclipse.wst.jsdt.js.node.common.util.JsonUtil

    public class JsonUtil
    extends java.lang.Object

JSON Utils for Gson

See Also:
  https://github.com/google/gson/blob/master/UserGuide.md

### Constructor Summary

Constructors
Constructor and Description
`JsonUtil()`

### Method Summary

All Methods Static Methods Concrete Methods
`static java.lang.String` `convertJavaObjectToJson(java.lang.Object jsonJavaObject)` Converts an Object to a JSON interpretation of that object.
`static <T> T` `convertJsonToJavaObject(java.lang.String jsonString, java.lang.Class<T> type)` Converts a JSON to an Object of type T, which is an interpretation of that JSON string.
`static <T> T` `readJsonFromFile(java.lang.String fileLocation, java.lang.Class<T> type)` Reads a JSON file at the specified location and returns an Object of the class type specified representing the JSON file attributes and values.
`static <T> T` `readJsonFromIFile(IFile json, java.lang.Class<T> type)` Reads a JSON file specified in the IFile and returns an Object of the class type specified representing the JSON file attributes and values.
`static void` `writeJsonToFile(java.io.File fileDestination, java.lang.Object jsonJavaObject)`
`static void` `writeJsonToFile(java.lang.String fileDestination, java.lang.Object jsonJavaObject)` Writes a JSON file representation of the Object received at the specified destination.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### JsonUtil

    public JsonUtil()

### Method Detail

#### readJsonFromFile

    public static <T> T readJsonFromFile(java.lang.String fileLocation,
                                         java.lang.Class<T> type)
                                  throws java.io.FileNotFoundException

Reads a JSON file at the specified location and returns an Object of the class type specified representing the JSON file attributes and values. This method will always return an Object of the type specified,

Parameters:
  `fileLocation` - The absolute path of the JSON file
  `type` - Class type to be use to represent the JSON format file
Returns:
Throws:
  `java.io.FileNotFoundException`

#### readJsonFromIFile

    public static <T> T readJsonFromIFile(IFile json,
                                          java.lang.Class<T> type)

Reads a JSON file specified in the IFile and returns an Object of the class type specified representing the JSON file attributes and values. This method will always return an Object of the type specified.

Parameters:
  `json` - The IFIle containing the JSON file
  `type` - Class type to be use to map the json attribute:value pairs
Returns:
  An Object of type T representing the JSON format string, null otherwise.

#### writeJsonToFile

    public static void writeJsonToFile(java.lang.String fileDestination,
                                       java.lang.Object jsonJavaObject)
                                throws java.io.IOException

Writes a JSON file representation of the Object received at the specified destination.

Parameters:
  `fileDestination` - Absolute path where the JSON file will be written.
  `jsonJavaObject` - The object to be represented as a JSON.
Throws:
  `java.io.IOException` - if the named file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.

#### writeJsonToFile

    public static void writeJsonToFile(java.io.File fileDestination,
                                       java.lang.Object jsonJavaObject)
                                throws java.io.IOException

Throws:
  `java.io.IOException`

#### convertJavaObjectToJson

    public static java.lang.String convertJavaObjectToJson(java.lang.Object jsonJavaObject)

Converts an Object to a JSON interpretation of that object.

Parameters:
  `jsonJavaObject` - The object to be converted.
Returns:
  JSON object as string.

#### convertJsonToJavaObject

    public static <T> T convertJsonToJavaObject(java.lang.String jsonString,
                                                java.lang.Class<T> type)

Converts a JSON to an Object of type T, which is an interpretation of that JSON string.

Parameters:
  `jsonString` - JSON format string.
  `type` - Class type to be use to represent the JSON format string
Returns:
  An Object of type T representing the JSON input string.