org.springframework.batch.core.repository.dao

## Class Jackson2ExecutionContextStringSerializer

- java.lang.Object
- - org.springframework.batch.core.repository.dao.Jackson2ExecutionContextStringSerializer

- All Implemented Interfaces:
    ExecutionContextSerializer, org.springframework.core.serializer.Deserializer<java.util.Map<java.lang.String,java.lang.Object>>, org.springframework.core.serializer.Serializer<java.util.Map<java.lang.String,java.lang.Object>>

      public class Jackson2ExecutionContextStringSerializer
      extends java.lang.Object
      implements ExecutionContextSerializer

  Implementation that uses Jackson2 to provide (de)serialization. By default, this implementation trusts a limited set of classes to be deserialized from the execution context. If a class is not trusted by default and is safe to deserialize, you can add it to the base set of trusted classes at `construction time` or provide an explicit mapping using Jackson annotations, as shown in the following example:

           @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
           public class MyTrustedType implements Serializable {

           }

  It is also possible to provide a custom `ObjectMapper` with a mixin for the trusted type:

           ObjectMapper objectMapper = new ObjectMapper();
           objectMapper.addMixIn(MyTrustedType.class, Object.class);
           Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
           serializer.setObjectMapper(objectMapper);
           // register serializer in JobRepositoryFactoryBean

  If the (de)serialization is only done by a trusted source, you can also enable default typing:

           PolymorphicTypeValidator polymorphicTypeValidator = .. // configure your trusted PolymorphicTypeValidator
           ObjectMapper objectMapper = new ObjectMapper();
           objectMapper.activateDefaultTyping(polymorphicTypeValidator);
           Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer();
           serializer.setObjectMapper(objectMapper);
           // register serializer in JobRepositoryFactoryBean

  Since:
    3.0.7
  Author:
    Marten Deinum, Mahmoud Ben Hassine
  See Also:
    `ExecutionContextSerializer`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Jackson2ExecutionContextStringSerializer(java.lang.String... trustedClassNames)` Create a new `Jackson2ExecutionContextStringSerializer`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.Map<java.lang.String,java.lang.Object>` | `deserialize(java.io.InputStream in)`
    `void` | `serialize(java.util.Map<java.lang.String,java.lang.Object> context, java.io.OutputStream out)`
    `void` | `setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.springframework.core.serializer.Serializer

      `serializeToByteArray`

    - ### Methods inherited from interface org.springframework.core.serializer.Deserializer

      `deserializeFromByteArray`

- - ### Constructor Detail

    - #### Jackson2ExecutionContextStringSerializer

          public Jackson2ExecutionContextStringSerializer(java.lang.String... trustedClassNames)

      Create a new `Jackson2ExecutionContextStringSerializer`.
      Parameters:
        `trustedClassNames` - fully qualified names of classes that are safe to deserialize from the execution context and which should be added to the default set of trusted classes.

  - ### Method Detail

    - #### setObjectMapper

          public void setObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)

    - #### deserialize

          public java.util.Map<java.lang.String,java.lang.Object> deserialize(java.io.InputStream in)
                                                                       throws java.io.IOException

      Specified by:
        `deserialize` in interface `org.springframework.core.serializer.Deserializer<java.util.Map<java.lang.String,java.lang.Object>>`
      Throws:
        `java.io.IOException`

    - #### serialize

          public void serialize(java.util.Map<java.lang.String,java.lang.Object> context,
                                java.io.OutputStream out)
                         throws java.io.IOException

      Specified by:
        `serialize` in interface `org.springframework.core.serializer.Serializer<java.util.Map<java.lang.String,java.lang.Object>>`
      Throws:
        `java.io.IOException`