Class ParameterBindingDocumentCodec

java.lang.Object
org.springframework.data.mongodb.util.json.ParameterBindingDocumentCodec
All Implemented Interfaces:
org.bson.codecs.Codec<org.bson.Document>, org.bson.codecs.CollectibleCodec<org.bson.Document>, org.bson.codecs.Decoder<org.bson.Document>, org.bson.codecs.Encoder<org.bson.Document>

public class ParameterBindingDocumentCodec extends Object implements org.bson.codecs.CollectibleCodec<org.bson.Document>
A Codec implementation that allows binding parameters to placeholders or SpEL expressions when decoding a JSON String.
Modified version of MongoDB Inc. DocumentCodec licensed under the Apache License, Version 2.0.
Since:
2.2
Author:
Jeff Yemin, Ross Lawley, Ralph Schaer, Christoph Strobl, Rocco Lagrotteria
  • Constructor Details

    • ParameterBindingDocumentCodec

      public ParameterBindingDocumentCodec()
      Construct a new instance with a default CodecRegistry.
    • ParameterBindingDocumentCodec

      public ParameterBindingDocumentCodec(org.bson.codecs.configuration.CodecRegistry registry)
      Construct a new instance with the given registry.
      Parameters:
      registry - the registry
    • ParameterBindingDocumentCodec

      public ParameterBindingDocumentCodec(org.bson.codecs.configuration.CodecRegistry registry, org.bson.codecs.BsonTypeClassMap bsonTypeClassMap)
      Construct a new instance with the given registry and BSON type class map.
      Parameters:
      registry - the registry
      bsonTypeClassMap - the BSON type class map
    • ParameterBindingDocumentCodec

      public ParameterBindingDocumentCodec(org.bson.codecs.configuration.CodecRegistry registry, org.bson.codecs.BsonTypeClassMap bsonTypeClassMap, org.bson.Transformer valueTransformer)
      Construct a new instance with the given registry and BSON type class map. The transformer is applied as a last step when decoding values, which allows users of this codec to control the decoding process. For example, a user of this class could substitute a value decoded as a Document with an instance of a special purpose class (e.g., one representing a DBRef in MongoDB).
      Parameters:
      registry - the registry
      bsonTypeClassMap - the BSON type class map
      valueTransformer - the value transformer to use as a final step when decoding the value of any field in the document
  • Method Details

    • documentHasId

      public boolean documentHasId(org.bson.Document document)
      Specified by:
      documentHasId in interface org.bson.codecs.CollectibleCodec<org.bson.Document>
    • getDocumentId

      public org.bson.BsonValue getDocumentId(org.bson.Document document)
      Specified by:
      getDocumentId in interface org.bson.codecs.CollectibleCodec<org.bson.Document>
    • generateIdIfAbsentFromDocument

      public org.bson.Document generateIdIfAbsentFromDocument(org.bson.Document document)
      Specified by:
      generateIdIfAbsentFromDocument in interface org.bson.codecs.CollectibleCodec<org.bson.Document>
    • encode

      public void encode(org.bson.BsonWriter writer, org.bson.Document document, org.bson.codecs.EncoderContext encoderContext)
      Specified by:
      encode in interface org.bson.codecs.Encoder<org.bson.Document>
    • decode

      public org.bson.Document decode(@Nullable String json, Object[] values)
    • decode

      public org.bson.Document decode(@Nullable String json, ParameterBindingContext bindingContext)
    • captureExpressionDependencies

      public org.springframework.data.spel.ExpressionDependencies captureExpressionDependencies(@Nullable String json, ValueProvider valueProvider, ExpressionParser expressionParser)
      Determine ExpressionDependencies from Expressions that are nested in the json content. Returns Optional.empty() if json is empty or of it does not contain any SpEL expressions.
      Parameters:
      json -
      expressionParser -
      Returns:
      merged ExpressionDependencies object if expressions were found, otherwise ExpressionDependencies.none().
      Since:
      3.1
    • decode

      public org.bson.Document decode(org.bson.BsonReader reader, org.bson.codecs.DecoderContext decoderContext)
      Specified by:
      decode in interface org.bson.codecs.Decoder<org.bson.Document>
    • getEncoderClass

      public Class<org.bson.Document> getEncoderClass()
      Specified by:
      getEncoderClass in interface org.bson.codecs.Encoder<org.bson.Document>