org.springframework.data.mongodb.core.query

Class SerializationUtils

  • java.lang.Object
    • org.springframework.data.mongodb.core.query.SerializationUtils


  • public abstract class SerializationUtils
    extends Object
    Utility methods for JSON serialization.
    Author:
    Oliver Gierke, Christoph Strobl, Mark Paluch
    • Method Detail

      • flattenMap

        public static Map<String,Object> flattenMap(@Nullable
                                                    org.bson.Document source)
        Flattens out a given Document.
         
         {
           _id : 1
           nested : { value : "conflux"}
         }
         
         will result in
         
         {
           _id : 1
           nested.value : "conflux"
         }
         
         
        Parameters:
        source - can be null.
        Returns:
        Collections.emptyMap() when source is null
        Since:
        1.8
      • serializeToJsonSafely

        @Nullable
        public static String serializeToJsonSafely(@Nullable
                                                             Object value)
        Serializes the given object into pseudo-JSON meaning it's trying to create a JSON representation as far as possible but falling back to the given object's Object.toString() method if it's not serializable. Useful for printing raw Documents containing complex values before actually converting them into Mongo native types.
        Parameters:
        value -
        Returns:
        the serialized value or null.