// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.serializer.json.jackson;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Fluent builder class that configures and instantiates instances of {@link JacksonJsonSerializer}.
 */
public final class JacksonJsonSerializerBuilder {
    private ObjectMapper objectMapper;

    /**
     * Constructs a new instance of {@link JacksonJsonSerializer} with the configurations set in this builder.
     *
     * @return A new instance of {@link JacksonJsonSerializer}.
     */
    public JacksonJsonSerializer build() {
        if (objectMapper == null) {
            return new JacksonJsonSerializer(new ObjectMapper());
        }
        return new JacksonJsonSerializer(objectMapper);
    }

    /**
     * Sets the {@link ObjectMapper} that will be used during serialization.
     * <p>
     * If this is set to {@code null} the default {@link ObjectMapper} will be used.
     *
     * @param objectMapper {@link ObjectMapper} that will be used during serialization.
     * @return The updated JacksonJsonSerializerBuilder class.
     */
    public JacksonJsonSerializerBuilder serializer(ObjectMapper objectMapper) {
        this.objectMapper = objectMapper;
        return this;
    }
}

@@ -139,16 +139,179 @@
 ckson;%0A%0A
+import com.azure.core.util.serializer.JacksonAdapter;%0Aimport com.fasterxml.jackson.annotation.JsonAutoDetect;%0Aimport com.fasterxml.jackson.annotation.JsonInclude;%0A
 import c
@@ -514,16 +514,600 @@
 ilder %7B%0A
+    /*%0A     * The ObjectMapper used by JacksonAdapter uses inclusion scopes and null handling that differs from the default%0A     * Jackson uses. This configuration is reset here by mutating the inclusion scope and null handling to use the%0A     * default Jackson values so that JacksonJsonSerializer has less friction when this default is used.%0A     */%0A    private static final ObjectMapper DEFAULT_MAPPER = new JacksonAdapter().serializer()%0A        .setSerializationInclusion(JsonInclude.Include.USE_DEFAULTS)%0A        .setDefaultVisibility(JsonAutoDetect.Value.defaultVisibility());%0A%0A
     priv
@@ -1387,18 +1387,22 @@
         
-if
+return
  (object
@@ -1416,18 +1416,16 @@
 == null)
- %7B
 %0A       
@@ -1421,38 +1421,33 @@
 ll)%0A            
-return
+?
  new JacksonJson
@@ -1461,36 +1461,31 @@
 zer(
-new ObjectMapper());
+DEFAULT_MAPPER)
 %0A       
  %7D%0A 
@@ -1484,25 +1484,14 @@
     
- %7D%0A
      
-   return
+:
  new
@@ -1673,53 +1673,125 @@
 ll%7D 
-the default %7B@link ObjectMapper%7D will be used
+%7B@link JacksonAdapter#serializer()%7D with default visibility and non-null inclusion%0A     * will be used as the default
 .%0A  

Update Default ObjectMapper used by JacksonJsonSerializer (#16889)