Class StorageSerializer
java.lang.Object
dev.crafty.core.storage.serialization.StorageSerializer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TConverts a JSON string to an object.static <T> TConverts a JSON string to an object with generic type parameters.static <T> TConverts a Map to an object.static <T> TConverts a YAML string to an object.static com.fasterxml.jackson.databind.ObjectMapperGets the JSON ObjectMapper instance.static com.fasterxml.jackson.databind.ObjectMapperGets the YAML ObjectMapper instance.static StringConverts an object to a JSON string.Converts an object to a Map.static StringConverts an object to a YAML string.
-
Constructor Details
-
StorageSerializer
public StorageSerializer()
-
-
Method Details
-
toJson
public static String toJson(Object object) throws com.fasterxml.jackson.core.JsonProcessingException Converts an object to a JSON string.- Parameters:
object- The object to serialize- Returns:
- The JSON string representation of the object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If serialization fails
-
fromJson
Converts a JSON string to an object.- Type Parameters:
T- The type of the object- Parameters:
json- The JSON string to deserializevalueType- The class of the object to create- Returns:
- The deserialized object
- Throws:
IOException- If deserialization fails
-
fromJson
public static <T> T fromJson(String json, Class<T> valueType, Class<?>... parameterClasses) throws IOException Converts a JSON string to an object with generic type parameters.- Type Parameters:
T- The type of the object- Parameters:
json- The JSON string to deserializevalueType- The class of the object to createparameterClasses- The classes of the generic type parameters- Returns:
- The deserialized object
- Throws:
IOException- If deserialization fails
-
toYaml
public static String toYaml(Object object) throws com.fasterxml.jackson.core.JsonProcessingException Converts an object to a YAML string.- Parameters:
object- The object to serialize- Returns:
- The YAML string representation of the object
- Throws:
com.fasterxml.jackson.core.JsonProcessingException- If serialization fails
-
fromYaml
Converts a YAML string to an object.- Type Parameters:
T- The type of the object- Parameters:
yaml- The YAML string to deserializevalueType- The class of the object to create- Returns:
- The deserialized object
- Throws:
IOException- If deserialization fails
-
toMap
Converts an object to a Map.- Parameters:
object- The object to convert- Returns:
- A Map representation of the object
-
fromMap
Converts a Map to an object.- Type Parameters:
T- The type of the object- Parameters:
map- The map to convertvalueType- The class of the object to create- Returns:
- The converted object
-
getJsonMapper
public static com.fasterxml.jackson.databind.ObjectMapper getJsonMapper()Gets the JSON ObjectMapper instance.- Returns:
- The JSON ObjectMapper
-
getYamlMapper
public static com.fasterxml.jackson.databind.ObjectMapper getYamlMapper()Gets the YAML ObjectMapper instance.- Returns:
- The YAML ObjectMapper
-