0

What is the default padding for int field in BeanIO if nothing is specified? For example in the following case:

Here I do not have padding mentioned for salary field, so what would be the value when marshalled to stream for salary=8888? Will it be 008888 or 8888 (2 spaces followed by 8888)?

  <stream name="employeeFile">
    <record name="employee" class="example.Employee">
      <field name="firstName" length="10" />
      <field name="salary" length="6" justify="right" />
    </record> 
  </stream>
Mikael
  • 969
  • 12
  • 24
Learner
  • 1,503
  • 6
  • 23
  • 44
  • 1
    Have you tried marshalling that stream to see what it does? Have you read the documentation? Section 4.3.4 explain how padding works - http://beanio.org/2.1/docs/reference/index.html#FixedLengthFields – nicoschl Mar 21 '19 at 09:00
  • Yes, I went through the documentation on this link, but it's not clear what would be the padding for int field if not specified. – Learner Mar 23 '19 at 21:00

2 Answers2

1

Given your mapping.xml file, spaces will be used to pad the output when it is less than 6 digits long.

Using input of firstname = "Learner" and salaray = 8888, will produce the following output:

Learner     8888

There are 5 spaces in total between the end of the firstName (Learner) and the start of the salary's first digit (8). The first 3 spaces are the padding for the firstName field to make it of length 10. The next 2 spaces are the padding for the salaray field. The spaces appear in front of the salaray field because you specified that it should be right justified.

If you left it at the defaults, the salary field would be left justified, the default for all fields without specifying the justify attribute. Then the 2 spaces would be after the value of the salary field.

To see it better, let us change the mapping.xml file to use an asterisk (*) for padding the value of the firstName field and use a zero (0) for padding the salary field.

<stream name="employeeFile" format="fixedlength">
  <record name="employee" class="example.Employee">
    <field name="firstName" length="10" padding="*"/>
    <field name="salary" length="6" justify="right" padding="0"/>
  </record>
</stream>

This produces the following output:

Learner***008888
nicoschl
  • 2,346
  • 1
  • 17
  • 17
0

It will actually be 8888__ (an underscore being a space character)

By default, fixed length fields are left justified and padded with spaces [1]

Mikael
  • 969
  • 12
  • 24