How do I add xmlName attribute to a field in BeanIO using Java?

73 Views Asked by At

I am trying to add xmlName attribute to a field in my mapping file. Now I know I can add xmlName attribute to any field by adding it manually, but I want to know if it is possible to add it using Java code.

Here is my mapping.xml file:

beanio>

  <stream name="employees" format="xml">
    <record name="employee" class="example.Employee">
      <field name="firstName" />
      <field name="lastName" />
      <field name="title" />
      <field name="salary" />
      <field name="hireDate" type="date" />
    </record>
  </stream>
  
</beanio>

In the above file, I want to set xmlName attribute for my field firstName as fName. I have looked through BeanIO documentation, but I did not see any method that would help me add xmlName attribute using Java. Is there any way to accomplish this?

Thank you for all the help.

1

There are 1 best solutions below

5
OpticalEngineering On

you can refer to BuilderApiAndAnnotations and add xmlName attribute by FieldBuilder#xmlName(String xmlName)