public class JsonUtil
extends java.lang.Object
Constructor and Description |
---|
JsonUtil() |
Modifier and Type | Method and Description |
---|---|
static java.util.Optional<java.lang.Object> |
getNewInstance(java.lang.Class<?> clazz)
Returns a new instance of the given class, if it can be instantiated.
|
static boolean |
hasKeys(javax.json.JsonValue value,
java.lang.String... keys) |
static boolean |
hasZeroArgumentConstructor(java.lang.Class<?> clazz)
Returns whether the given class has a constructor taking zero arguments (and therefore clazz.newInstance works).
|
static java.util.Optional<javax.json.JsonValue> |
readFromFile(java.lang.String fileName)
Read the Json content from the given file.
|
static java.util.Optional<java.lang.Object> |
readObjectFromFile(java.lang.String fileName) |
static java.util.Optional<java.lang.Class<?>> |
tryGetClass(javax.json.JsonValue value,
java.lang.String typeField)
Tries to get the class stored in the JsonValue.
|
static void |
writeToFile(java.lang.String fileName,
javax.json.JsonValue json)
Write the given Json content to the given file.
|
static void |
writeToFile(java.lang.String fileName,
java.lang.Object object)
Write the given object to file, after trying to serialize it with the
Serializers.jsonSerializableSerializer()
serializer. |
public static java.util.Optional<java.lang.Class<?>> tryGetClass(javax.json.JsonValue value, java.lang.String typeField)
value
- The JsonValue from which to extract the type.typeField
- The name of the type field in the JsonValue.public static boolean hasZeroArgumentConstructor(java.lang.Class<?> clazz)
clazz
- The class to check.public static boolean hasKeys(javax.json.JsonValue value, java.lang.String... keys)
public static java.util.Optional<java.lang.Object> getNewInstance(java.lang.Class<?> clazz)
clazz
- The class to instantiate an instance from.public static void writeToFile(java.lang.String fileName, java.lang.Object object)
Serializers.jsonSerializableSerializer()
serializer.fileName
- The name of the file to store the Json inobject
- The object to convert to json and to store in the file.public static void writeToFile(java.lang.String fileName, javax.json.JsonValue json)
fileName
- The name of the file to store the Json in.json
- The Json content to store in the file.public static java.util.Optional<javax.json.JsonValue> readFromFile(java.lang.String fileName)
fileName
- The name of the file to get the Json from.public static java.util.Optional<java.lang.Object> readObjectFromFile(java.lang.String fileName)