merge method
Merges the current options with the provided options, creating a new instance.
When merging, the provided options take precedence. Lists are concatenated, and the jsonNamingConvention from the provided options is used if available.
@param options The options to merge with. If null, returns a copy of current options.
@returns A new JsonSerializerOptions instance with merged configuration.
Implementation
JsonSerializerOptions merge(JsonSerializerOptions? options) {
if (options == null) {
return JsonSerializerOptions(
types: [...types],
converters: [...converters],
namingConventions: [...namingConventions],
jsonNamingConvention: jsonNamingConvention,
);
}
return JsonSerializerOptions(
types: [...types, ...options.types],
converters: [...converters, ...options.converters],
namingConventions: [...namingConventions, ...options.namingConventions],
jsonNamingConvention:
options.jsonNamingConvention ?? jsonNamingConvention,
);
}