File

projects/wms-framework/src/lib/baseframework/TypeSerializers/SimpleDictionarySerializer.ts

Description

Defines a custom Serializer/deserializer for a SimpleDictionary object. Current support includes elements with basic datatype only in both key and value

Implements

SerializerAndDeserializer

Index

Methods

Methods

Deserialize
Deserialize(obj: unknown)

Deserializes a SimpleDictionary object. The serialized representation is an array of elements [{Key,Value} ...] objects.

Parameters :
Name Type Optional
obj unknown No
Returns : SimpleDictionary<unknown, unknown>

{SimpleDictionary<unknown, unknown>}

Serialize
Serialize(object: SimpleDictionary)

Not supported

Parameters :
Name Type Optional
object SimpleDictionary<unknown | unknown> No
Returns : void
import { SimpleDictionary } from '../SimpleDictionary';
import { SerializerAndDeserializer } from './SerializerFactory';

/*****************************************************************************
 * Copyright (C) Mobilize.Net <info@mobilize.net> - All Rights Reserved
 *
 * This file is part of the Mobilize Frameworks, which is
 * proprietary and confidential.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Mobilize.Net Corporation.
 * The intellectual and technical concepts contained herein are
 * proprietary to Mobilize.Net Corporation and may be covered
 * by U.S. Patents, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Mobilize.Net Corporation.
 ******************************************************************************/
/**
 * Defines a custom Serializer/deserializer for a {@link SimpleDictionary} object.  Current support includes
 * elements with basic datatype only in both key and value
 *
 * @export
 * @class SimpleDictionarySerializer
 * @implements {SerializerAndDeserializer<SimpleDictionary<unknown, unknown>>}
 */
export class SimpleDictionarySerializer
  implements SerializerAndDeserializer<SimpleDictionary<unknown, unknown>>
{
  /**
   * Deserializes a {@link SimpleDictionary} object.  The serialized representation is an array of elements [{Key,Value} ...] objects.
   *
   * @param {unknown} obj
   * @return {*}  {SimpleDictionary<unknown, unknown>}
   * @memberof SimpleDictionarySerializer
   */
  Deserialize(obj: unknown): SimpleDictionary<unknown, unknown> {
    if (Array.isArray(obj)) {
      let dict: SimpleDictionary<unknown, unknown> = new SimpleDictionary();
      obj.forEach((x) => dict.addEntry(x.Key, x.Value));
      return dict;
    } else {
      return null;
    }
  }

  /**
   * Not supported
   *
   * @param {SimpleDictionary<unknown, unknown>} object
   * @memberof SimpleDictionarySerializer
   */
  Serialize(object: SimpleDictionary<unknown, unknown>) {
    throw new Error('Method not implemented.');
  }
}

result-matching ""

    No results matching ""