Skip to content

FixedLengthTypeMapper ComplexProperty #79

@zcharleshebert

Description

@zcharleshebert

Describe the bug
When you use a FixedLengthTypeMapper with ComplexProperty for a given window length, it seems to trim the value of that window prior to pass it to the ComplexProperty's mapper and thus throwing an exception saying the record length does not match the schema.

To Reproduce
Steps to reproduce the behaviour:

        class Person
        {
            public string Name { get; set; }
            public Pet Pet1 { get; set; }
            public Pet Pet2 { get; set; }

        }
        class Pet
        {
            public string Name { get; set; }
            public string UniversalPetIdentifier { get; set; }
            
        }
        
        [Fact]
        void Test()
        {
            var personMapper = FixedLengthTypeMapper.Define<Person>();
            personMapper.Property(f => f.Name, new Window(10));
            personMapper.Ignored(new Window(1));
            
            var petMapper = FixedLengthTypeMapper.Define<Pet>();
            petMapper.Property(pet => pet.Name, new Window(10));
            petMapper.Property(pet => pet.UniversalPetIdentifier, new Window(5));
            petMapper.Ignored(new Window(2));

            personMapper.ComplexProperty(p => p.Pet1, petMapper, new Window(17));
            personMapper.ComplexProperty(p => p.Pet2, petMapper, new Window(17));

            var line = "John       Doggy     dog01  Rain      cat01  ";

            var reader = personMapper.GetReader(new StringReader(line));
            var persons = reader.ReadAll().ToList();
            
            // Throws The record did not meet the length requirements specified in the schema. Record 1.
            // The ColumnValue that is throwing the exception is: Doggy     dog01
            // It has a length of 15 instead of 17.
        }

Expected behaviour
I expect that the value is not trimmed prior to pass it to the ComplexProperty's mapper and that the length match the schema.

Version:
4.16

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