FieldBuilderOptions.java

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

  3. package com.azure.search.documents.indexes.models;

  4. import com.azure.core.annotation.Fluent;
  5. import com.azure.core.util.serializer.JsonSerializer;
  6. import com.azure.core.util.serializer.MemberNameConverter;
  7. import com.azure.core.util.serializer.MemberNameConverterProviders;
  8. import com.azure.search.documents.indexes.SearchIndexAsyncClient;
  9. import com.azure.search.documents.indexes.SearchIndexClient;

  10. import java.util.Objects;

  11. /**
  12.  * Additional parameters to build {@link SearchField}.
  13.  */
  14. @Fluent
  15. public final class FieldBuilderOptions {
  16.     private JsonSerializer jsonSerializer;

  17.     /**
  18.      * Gets the serializer used to aid the construction of {@link SearchField SearchFields} in {@link
  19.      * SearchIndexClient#buildSearchFields(Class, FieldBuilderOptions)} buildSearchFields} or {@link
  20.      * SearchIndexAsyncClient#buildSearchFields(Class, FieldBuilderOptions) buildSearchFields}.
  21.      * <p>
  22.      * If {@link JsonSerializer} is {@code null} or doesn't implement the {@link MemberNameConverter} interface then
  23.      * {@link MemberNameConverterProviders#createInstance()} will be used to provide a converter from the classpath.
  24.      *
  25.      * @return The custom {@link JsonSerializer}.
  26.      */
  27.     public JsonSerializer getJsonSerializer() {
  28.         return jsonSerializer;
  29.     }

  30.     /**
  31.      * Sets the serializer.
  32.      * <p>
  33.      * For building {@link SearchField SearchFields} it is expected that the {@link JsonSerializer} passed also
  34.      * implements the {@link MemberNameConverter} interface. If it doesn't {@link
  35.      * MemberNameConverterProviders#createInstance()} will be used to provide a converter from the classpath.
  36.      *
  37.      * @param jsonSerializer The custom serializer.
  38.      * @return The updated FieldBuilderOptions object.
  39.      */
  40.     public FieldBuilderOptions setJsonSerializer(JsonSerializer jsonSerializer) {
  41.         this.jsonSerializer = Objects.requireNonNull(jsonSerializer, "'jsonSerializer' cannot be null");
  42.         return this;
  43.     }


  44. }