Skip to content

When return from property is nil it does not continue to mapper #19

@arturictus

Description

@arturictus

This are my mappers:
I've changed the initalize if the input is nil would build and empty skeleton.

class MobileConfigMapper < HashMap::Base
    transforms_output HashMap::UnderscoreKeys

    def initialize(hash)
      input = hash || {}
      super(input)
    end

    properties 'EnableBookingAir',
               'EnableChangeAir',
               'EnableCancelAir',
               'EnableBookingHotel',
               'EnableChangeHotel',
               'EnableCancelHotel',
               'EnableBookingCar',
               'EnableChangeCar',
               'EnableCancelCar',
               'EnableCertify',
               'EnableLyft',
               'EnableGoogleFlights',
               'EnableHilton',
               'EnableProfileAccess',
               'EnableSecureLocateMe',
               'EnableEULA'
  end

  class CompanySettingsMapper < HashMap::Base
    transforms_output HashMap::UnderscoreKeys
    from_child 'CompanySettings' do
      from_child 'CompanyIdentity' do
        property 'CompanyGuid'
      end
      properties 'IsCertifyEnabled', 'IsProfileEnabled'
      property 'PathMobileConfig', mapper: MobileConfigMapper
    end
  end

hash:

{
  "StatusCode": 200,
  "ErrorDescription": null,
  "Messages": null,
  "CompanySettings": {
    "CompanyIdentity": {
      "CompanyGuid": "0A6005FA-161D-4290-BB7D-B21B14313807",
      "PseudoCity": {
        "Code": "PARTQ2447"
      }
    },
    "IsCertifyEnabled": false,
    "IsProfileEnabled": true,
    "PathMobileConfig": null
  }
}

I expect PathMobileConfig or it's transformation path_mobile_config to be {} but it always returns `nil``

For now I will use the block turnaround:

property 'PathMobileConfig' do |settings|
  if hash = settings['PathMobileConfig']
    MobileConfigMapper.call(hash)
  else
    {}
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions