# ConverterService Class

Module
import { ConverterService } from "@tsed/common"
Source/packages/common/src/mvc/services/ConverterService.ts

# Overview

class ConverterService {
<span class="token keyword">constructor</span><span class="token punctuation">(</span>injectorService<span class="token punctuation">:</span> <a href="/api/di/services/InjectorService.html"><span class="token">InjectorService</span></a><span class="token punctuation">,</span> configuration<span class="token punctuation">:</span> <a href="/api/di/decorators/Configuration.html"><span class="token">Configuration</span></a><span class="token punctuation">)</span><span class="token punctuation">;</span>
/**
 * Convert instance to plainObject.
 *
 * @param obj
 * @param options
 */
<span class="token function">serialize</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> <a href="/api/json-mapper/utils/JsonSerializerOptions.html"><span class="token">JsonSerializerOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
/**
 * @deprecated Since v6.
 */
<span class="token function">serialize</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> <a href="/api/common/mvc/services/ConverterOptions.html"><span class="token">ConverterOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
/**
 * @deprecated Since v6. <a href="/api/common/mvc/decorators/method/Use.html"><span class="token">Use</span></a> classToPlainObject <span class="token keyword">from</span> @tsed/json-mapper instead
 */
<span class="token function">serializeClass</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> <a href="/api/common/mvc/services/ConverterOptions.html"><span class="token">ConverterOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
/**
 * Convert a plainObject to targetType.
 *
 * ### <a href="/api/common/mvc/decorators/method/Options.html"><span class="token">Options</span></a>
 *
 * - `ignoreCallback`<span class="token punctuation">:</span> callback called for each object which will be deserialized. The callback can return a <span class="token keyword">boolean</span> to avoid the default converter behavior.
 * - `checkRequiredValue`<span class="token punctuation">:</span> Disable the required check condition.
 *
 * @param obj Object source that will be deserialized
 * @param options Mapping options
 * @returns <span class="token punctuation">{</span><span class="token keyword">any</span><span class="token punctuation">}</span>
 */
<span class="token function">deserialize</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> <a href="/api/json-mapper/utils/JsonDeserializerOptions.html"><span class="token">JsonDeserializerOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token function">deserialize</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> type<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> <a href="/api/common/mvc/services/ConverterOptions.html"><span class="token">ConverterOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
/**
 * @deprecated Since v6.
 */
<span class="token function">deserialize</span><span class="token punctuation">(</span>obj<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> collectionType<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> baseType<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> options?<span class="token punctuation">:</span> <a href="/api/common/mvc/services/ConverterOptions.html"><span class="token">ConverterOptions</span></a><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>

}

# Members

serialize(obj: any, options?: JsonSerializerOptions): any;

Convert instance to plainObject.


serialize(obj: any, options?: ConverterOptions): any;

serializeClass(obj: any, options?: ConverterOptions): {};

deserialize(obj: any, options?: JsonDeserializerOptions): any;
Param Type Description
obj any Object source that will be deserialized options

Convert a plainObject to targetType.

# Options

  • ignoreCallback: callback called for each object which will be deserialized. The callback can return a boolean to avoid the default converter behavior.
  • checkRequiredValue: Disable the required check condition.

deserialize(obj: any, type: any, options?: ConverterOptions): any;

deserialize(obj: any, collectionType: any, baseType: any, options?: ConverterOptions): any;

Other topics