SerializationContext
Keywords: net.corda.core.serialization.SerializationContext interface
Date: 2023-09-18

net.corda.core.serialization

## Interface SerializationContext

-     @DoNotImplement
      public SerializationContext

  Parameters to serialization and deserialization.

- - ### Constructor Detail

    - #### SerializationContext

          public SerializationContext()

  - ### Method Detail

    - #### getPreferredSerializationVersion

          @NotNull
          ByteSequence getPreferredSerializationVersion()

      When serializing, use the format this header sequence represents.

    - #### getEncoding

          @Nullable
          SerializationEncoding getEncoding()

      If non-null, apply this encoding (typically compression) when serializing.

    - #### getDeserializationClassLoader

          @NotNull
          java.lang.ClassLoader getDeserializationClassLoader()

      The class loader to use for deserialization.

    - #### getWhitelist

          @NotNull
          ClassWhitelist getWhitelist()

      A whitelist that contains (mostly for security purposes) which classes can be serialized and deserialized.

    - #### getEncodingWhitelist

          @NotNull
          EncodingWhitelist getEncodingWhitelist()

      A whitelist that determines (mostly for security purposes) whether a particular encoding may be used when deserializing.

    - #### getProperties

          @NotNull
          java.util.Map<java.lang.Object,java.lang.Object> getProperties()

      A map of any additional properties specific to the particular use case.

    - #### getObjectReferencesEnabled

          boolean getObjectReferencesEnabled()

      Duplicate references to the same object preserved in the wire format and when deserialized when this is true, otherwise they appear as new copies of the object.

    - #### getLenientCarpenterEnabled

          boolean getLenientCarpenterEnabled()

      If true the carpenter will happily synthesis classes that implement interfaces containing methods that are not getters for any AMQP fields. Invoking these methods will throw an AbstractMethodError. If false then an exception will be thrown during deserialization instead.

      The default is false.

      See Also:
        AbstractMethodError

    - #### getCarpenterDisabled

          boolean getCarpenterDisabled()

      If true, deserialization calls using this context will not fallback to using the Class Carpenter to attempt to construct classes present in the schema but not on the current classpath.

      The default is false.

    - #### getPreventDataLoss

          boolean getPreventDataLoss()

      If true the serialization evolver will fail if the binary to be deserialized contains more fields then the current object from the classpath.

      The default is false.

    - #### getUseCase

          @NotNull
          net.corda.core.serialization.SerializationContext.UseCase getUseCase()

      The use case we are serializing or deserializing for. See `enum SerializationContext.UseCase`.

      See Also:
        `enum SerializationContext.UseCase`

    - #### getCustomSerializers

          @NotNull
          java.util.Set<net.corda.core.serialization.SerializationCustomSerializer> getCustomSerializers()

      Additional custom serializers that will be made available during (de)serialization.

    - #### withProperty

          @NotNull
          SerializationContext withProperty(@NotNull
                                                     java.lang.Object property,
                                                     @NotNull
                                                     java.lang.Object value)

      Helper method to return a new context based on this context with the property added.

    - #### withProperties

          @NotNull
          SerializationContext withProperties(@NotNull
                                                       java.util.Map<java.lang.Object,? extends java.lang.Object> extraProperties)

      Helper method to return a new context based on this context with the extra properties added.

    - #### withoutReferences

          @NotNull
          SerializationContext withoutReferences()

      Helper method to return a new context based on this context with object references disabled.

    - #### withLenientCarpenter

          @NotNull
          SerializationContext withLenientCarpenter()

      Return a new context based on this one but with a lenient carpenter.

      See Also:
        `lenientCarpenterEnabled`

    - #### withoutCarpenter

          @NotNull
          SerializationContext withoutCarpenter()

      Returns a copy of the current context with carpentry of unknown classes disabled. On encountering such a class during deserialization the Serialization framework will throw a NotSerializableException.

      See Also:
        NotSerializableException

    - #### withPreventDataLoss

          @NotNull
          SerializationContext withPreventDataLoss()

      Return a new context based on this one but with a strict evolution.

      See Also:
        `preventDataLoss`

    - #### withClassLoader

          @NotNull
          SerializationContext withClassLoader(@NotNull
                                                        java.lang.ClassLoader classLoader)

      Helper method to return a new context based on this context with the deserialization class loader changed.

    - #### withAttachmentsClassLoader

          @Deprecated
           @NotNull
          SerializationContext withAttachmentsClassLoader(@NotNull
                                                                                java.util.List<? extends net.corda.core.crypto.SecureHash> attachmentHashes)

      Deprecated.

      Does not do anything.

    - #### withWhitelisted

          @NotNull
          SerializationContext withWhitelisted(@NotNull
                                                        java.lang.Class<?> clazz)

      Helper method to return a new context based on this context with the given class specifically whitelisted.

    - #### withCustomSerializers

          @NotNull
          SerializationContext withCustomSerializers(@NotNull
                                                              java.util.Set<? extends net.corda.core.serialization.SerializationCustomSerializer<?,?>> serializers)

      Helper method to return a new context based on this context with the given serializers added.

    - #### withPreferredSerializationVersion

          @NotNull
          SerializationContext withPreferredSerializationVersion(@NotNull
                                                                          ByteSequence magic)

      Helper method to return a new context based on this context but with serialization using the format this header sequence represents.

    - #### withEncoding

          @NotNull
          SerializationContext withEncoding(@Nullable
                                                     SerializationEncoding encoding)

      A shallow copy of this context but with the given (possibly null) encoding.

    - #### withEncodingWhitelist

          @NotNull
          SerializationContext withEncodingWhitelist(@NotNull
                                                              EncodingWhitelist encodingWhitelist)

      A shallow copy of this context but with the given encoding whitelist.