Class JacksonHelper

java.lang.Object
com.github.thought2code.mcp.annotated.util.JacksonHelper

public final class JacksonHelper extends Object
Helper class for Jackson JSON and YAML serialization and deserialization.

This class provides static methods for serializing and deserializing objects to and from JSON and YAML formats using Jackson.

Author:
codeboyzhou
  • Method Details

    • toJsonString

      public static String toJsonString(Object object)
      Serialize an object to a JSON string.
      Parameters:
      object - the object to serialize
      Returns:
      the JSON string representation of the object
    • fromJson

      public static <T> T fromJson(String json, Class<T> valueType)
      Deserialize a JSON string to an object of the specified type.
      Type Parameters:
      T - the type of the object to deserialize to
      Parameters:
      json - the JSON string to deserialize
      valueType - the class of the object to deserialize to
      Returns:
      the deserialized object
    • fromYaml

      public static <T> T fromYaml(File yamlFile, Class<T> valueType)
      Deserialize a YAML file to an object of the specified type.
      Type Parameters:
      T - the type of the object to deserialize to
      Parameters:
      yamlFile - the YAML file to deserialize
      valueType - the class of the object to deserialize to
      Returns:
      the deserialized object