Java Subclass Generation - 7.3

Talend Data Mapper User Guide

Version
7.3
Language
English
Product
Talend Big Data Platform
Talend Data Fabric
Talend Data Management Platform
Talend Data Services Platform
Talend MDM Platform
Talend Real-Time Big Data Platform
Module
Talend Studio
Content
Design and Development > Designing Jobs
Last publication date
2023-01-05

Often in a Java class, a field or property will refer to a (possibly abstract) class that has one or more subclasses. When mapping this field/property, it's important to be able to determine which concrete class was specified in the input, and in the output to specify the desired concrete class. It's important to note that the subclass handling applies to all subclasses known to the import (contained in the Jar files or folders being imported). There may be subclasses that exist but are not known to the import because they have not been specified.

There are two different strategies for handling subclassing:
  1. Emitting all Subclasses in a Sequence - This is convenient (and necessary) if you are using map inheritance combined with Java subclasses. Using this mechanism you can map elements in a superclass in a parent map, and map elements in a subclass in a child (inheriting) map and the superclass mappings will be properly inherited. The downside of this is that it's a little less automatic declaring the class you want to emit for the output. The declaring of the output class is done by modifying a Choice function in the value of the class element associated with the superclass. This is not done automatically. This is the default option.

    When this option is used a structure for the root of the inheritance tree with a name ending in _Composite is generated (in addition to all of the structures generated for each Java class). This composite structure contains all of the inherited structures in the inheritance tree for the field/property and can therefore be used as a structure in an inherited map.

  2. Emitting a Choice for Each Subclass - Each possible subclass is emitted as a member of a choice element with all of the properties associated with the subclass (and all superclasses). This means the superclass properties will be duplicated among members of the choice. If you are not using map inheritance, then this is probably fine and easy. It's also a bit easier because when you map something to an output subclass, it should automatically generate the correct Emit expression to indicate which subclass (member) is to be output.

The following options are provided for subclass generation:
  • Generate a sequence of elements for all possible subclasses (Default) - Implements the first strategy described above for all possible direct and descendent subclasses.

  • Generate only the elements for the specified class - Generates only the class specified by the field/property. Use this option if you don't use the subclasses in your mappings.

  • Generate a choice and a child for each direct and descendent subclass - Implements the second strategy above by generating a choice among the class of the field/property and all descendant subclasses. Use this option if the mappings can include any descendant subclass.

  • Generate a choice and a child for each direct subclass - Implements the second strategy above by generating a choice among the class of the field/property and the only direct subclasses of that class. Use this option if you only use the direct subclasses in your mappings.