Sha256: 9d0eff26bb098d82ac74075251478a855d6725b63a54260375dc03806e4de043

Contents?: true

Size: 1.53 KB

Versions: 22

Compression:

Stored size: 1.53 KB

Contents

---
title: Serialization
weight: 3
layout: guides
---

## Overview

LedgerSync leverages serialization and deserialization to convert resources into the necessary hash formats the ledger expects.  Generally, each resource will have 1 serializer and 1 deserializer.

## Serializers

Serializers take a `Resource` and output a hash.  For example:

```ruby
customer = LedgerSync::Ledgers::NetSuite::Customer.new(
  companyName: 'Test Company',
  external_id: 'ext_123'
)
serializer = LedgerSync::Ledgers::NetSuite::Customer::Serializer.new
serializer.serialize(resource: customer)
# Sample output:
# {
#   "companyName" => "Test Company",
#   "externalId" => "ext_123",
#   "email" => nil,
#   "phone" => nil,
#   "firstName" => nil,
#   "lastName" => nil,
#   "subsidiary" => nil
# }
end
```

## Deserializers

Deserializers take a hash and output a `Resource`.  For example:

```ruby
h = {
  "companyName" => "Test Company",
  "externalId" => "ext_123",
  "email" => nil,
  "id" => "987654321",
  "phone" => nil,
  "firstName" => nil,
  "lastName" => nil,
  "subsidiary" => nil
}

deserializer = LedgerSync::Ledgers::NetSuite::Customer::Deserializer.new
customer = deserializer.deserialize(hash: h, resource: LedgerSync::Ledgers::NetSuite::Customer.new)
customer.ledger_id # => "987654321"
customer.companyName # => "Test Company"
```

## How to use

Serializers and deserializers are automatically inferred by each operation based on the naming convention.  It is possible to create your own serializers.  Please see [Customization](/guides/customization) for more.

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ledger_sync-2.6.0 documentation/site/guides/architecture/serialization.md
ledger_sync-2.5.0 documentation/site/guides/architecture/serialization.md
ledger_sync-2.4.4 documentation/site/guides/architecture/serialization.md
ledger_sync-2.3.1 documentation/site/guides/architecture/serialization.md
ledger_sync-2.2.3 documentation/site/guides/architecture/serialization.md
ledger_sync-2.2.1 documentation/site/guides/architecture/serialization.md
ledger_sync-2.2.0 documentation/site/guides/architecture/serialization.md
ledger_sync-2.0.2 documentation/site/guides/architecture/serialization.md
ledger_sync-2.0.1 documentation/site/guides/architecture/serialization.md
ledger_sync-2.0.0 documentation/site/guides/architecture/serialization.md
ledger_sync-2.0.0.pre.1 documentation/site/guides/architecture/serialization.md
ledger_sync-1.8.1 documentation/site/guides/architecture/serialization.md
ledger_sync-1.8.0 documentation/site/guides/architecture/serialization.md
ledger_sync-1.7.0 documentation/site/guides/architecture/serialization.md
ledger_sync-1.6.0 documentation/site/guides/architecture/serialization.md
ledger_sync-1.5.2 documentation/site/guides/architecture/serialization.md
ledger_sync-1.5.1 documentation/site/guides/architecture/serialization.md
ledger_sync-1.5.0 documentation/site/guides/architecture/serialization.md
ledger_sync-1.4.4 documentation/site/guides/architecture/serialization.md
ledger_sync-1.4.2 documentation/site/guides/architecture/serialization.md