Class MorpheusModelJsonUtility

java.lang.Object
com.morpheusdata.core.util.MorpheusModelJsonUtility

public class MorpheusModelJsonUtility extends Object
Utility class for serializing and deserializing MorpheusModel objects to/from JSON. Provides a consistent serialization format for MorpheusModel transport.

Uses a pre-configured ObjectMapper with:

  • ISO 8601 date formatting
  • GString serialization support (Groovy compatibility)

Usage:

   // Serialize
   Role role = new Role();
   role.setAuthority("DevOps");
   String json = MorpheusModelJsonUtility.serialize(role);

   // Deserialize
   Role restored = MorpheusModelJsonUtility.deserialize(json, Role.class);

   // Lists
   String listJson = MorpheusModelJsonUtility.serializeList(roles);
   List<Role> roles = MorpheusModelJsonUtility.deserializeList(listJson, Role.class);
 
Since:
1.4.1
  • Constructor Details

    • MorpheusModelJsonUtility

      public MorpheusModelJsonUtility()
  • Method Details

    • serialize

      public static <T extends MorpheusModel> String serialize(T model) throws com.fasterxml.jackson.core.JsonProcessingException
      Serialize a single MorpheusModel instance to JSON.
      Type Parameters:
      T - the model type
      Parameters:
      model - the model to serialize
      Returns:
      JSON string representation
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if serialization fails
    • serializeList

      public static <T extends MorpheusModel> String serializeList(List<T> models) throws com.fasterxml.jackson.core.JsonProcessingException
      Serialize a list of MorpheusModel instances to JSON array.
      Type Parameters:
      T - the model type
      Parameters:
      models - the list of models to serialize
      Returns:
      JSON array string representation
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if serialization fails
    • serializeMap

      public static <T extends MorpheusModel> String serializeMap(Map<String,T> models) throws com.fasterxml.jackson.core.JsonProcessingException
      Serialize a map of String → MorpheusModel to JSON object.
      Type Parameters:
      T - the model type
      Parameters:
      models - the map to serialize
      Returns:
      JSON object string representation
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if serialization fails
    • deserialize

      public static <T extends MorpheusModel> T deserialize(String json, Class<T> modelClass) throws com.fasterxml.jackson.core.JsonProcessingException
      Deserialize a JSON string to a single MorpheusModel instance.
      Type Parameters:
      T - the model type
      Parameters:
      json - the JSON string
      modelClass - the target class
      Returns:
      deserialized model instance
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if deserialization fails
    • deserializeList

      public static <T extends MorpheusModel> List<T> deserializeList(String json, Class<T> modelClass) throws com.fasterxml.jackson.core.JsonProcessingException
      Deserialize a JSON array string to a list of MorpheusModel instances.
      Type Parameters:
      T - the model type
      Parameters:
      json - the JSON array string
      modelClass - the target element class
      Returns:
      list of deserialized model instances
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if deserialization fails
    • deserializeMap

      public static <T extends MorpheusModel> Map<String,T> deserializeMap(String json, Class<T> modelClass) throws com.fasterxml.jackson.core.JsonProcessingException
      Deserialize a JSON object string to a map of String → MorpheusModel.
      Type Parameters:
      T - the model type
      Parameters:
      json - the JSON object string
      modelClass - the target value class
      Returns:
      map of deserialized model instances
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException - if deserialization fails