fskorgen commented on issue #6972:
URL: https://github.com/apache/hop/issues/6972#issuecomment-4212769942

   @hansva One more question:
   
   When using the legacy getXml() functions, we often skip XML elements when 
the value is empty or equal to the default value. This is done to reduce the 
size of the generated XML.
   
   We have some projects where we read datalake files and load data into 
database tables. In these projects, we map many hundreds of tables with a large 
number of fields (up to 500). Omitting empty or default values helps keep the 
XML manageable, but it also means the deserialization logic must correctly 
handle missing elements and apply the expected defaults.
   
   Is there a way to define default values in the annotation and have values 
equal to those defaults be skipped during serialization?
   
   For example, for one field read from the datalake, the legacy getXml() code 
looks like this:
   
       for (CloudApiField field : argumentFields) {
         xml.append("      <field>").append(Const.CR);
         xml.append("        ").append(XmlHandler.addTagValue("name", 
field.getName()));
         xml.append("        ").append(XmlHandler.addTagValue("attribute", 
field.getAttribute()));
         xml.append("        ").append(XmlHandler.addTagValue("type", 
field.getTypeDesc()));
         if (Strings.isNotBlank(field.getFormat())) {
           xml.append("        ").append(XmlHandler.addTagValue("format", 
field.getFormat()));
         }
         xml.append("        ").append(XmlHandler.addTagValue("length", 
field.getLength()));
         if (field.getPrecision() != -1) {
           xml.append("        ").append(XmlHandler.addTagValue("precision", 
field.getPrecision()));
         }
         if (Strings.isNotBlank(field.getDecimalSymbol())) {
           xml.append("        ").append(XmlHandler.addTagValue("decimal", 
field.getDecimalSymbol()));
         }
         if (Strings.isNotBlank(field.getTrimTypeCode()) || 
"none".equals(field.getTrimTypeCode())) {
           xml.append("        ").append(XmlHandler.addTagValue("trim_type", 
field.getTrimTypeCode()));
         }
         if (Strings.isNotBlank(field.getComments())) {
           xml.append("        ").append(XmlHandler.addTagValue("comments", 
field.getComments()));
         }
         xml.append("      </field>").append(Const.CR);
       }
   
   With annotations, the XML becomes (e.g two fields):
   
       <field>
         <name>MBCONO</name>
         <attribute>[CONO]</attribute>
         <type>Integer</type>
         <length>3</length>
         <format>0</format>
         <trim_type>none</trim_type>
         <precision>-1</precision>
         <decimal/>
         <group/>
         <comments>company (x)</comments>
       </field>
       <field>
         <name>MBWHLO</name>
         <attribute>[WHLO]</attribute>
         <type>String</type>
         <length>3</length>
         <format/>
         <trim_type>none</trim_type>
         <precision>-1</precision>
         <decimal/>
         <group/>
         <comments>warehouse (x)</comments>
       </field>
   
   With the legacy method, the XML is:
   
       <field>
         <name>MBCONO</name>
         <attribute>[CONO]</attribute>
         <type>Integer</type>
         <format>0</format>
         <length>3</length>
         <comments>company (x)</comments>
       </field>
       <field>
         <name>MBWHLO</name>
         <attribute>[WHLO]</attribute>
         <type>String</type>
         <length>3</length>
         <comments>warehouse (x)</comments>
       </field>
   
   So the annotation-based approach produces significantly more XML for large 
mappings. It would be useful if annotations could support default values and 
omit fields that are empty or equal to those defaults, similar to the legacy 
behavior.
   
   If you want, I can also make this more concise and more natural for a GitHub 
issue comment.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to