[MDSAL-90] Simple type derivation relationship lost when binding DTO is translated to DOM and back. Created: 10/Jun/15 Updated: 24/Jul/23 |
|
| Status: | Confirmed |
| Project: | mdsal |
| Component/s: | Binding codegen, Binding runtime |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Low |
| Reporter: | Tony Tkacik | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| External issue ID: | 3658 | ||||||||
| Description |
|
Having model:
typedef uri {
type string;
}
typedef specialized-uri {
type uri;
}
container data {
leaf value {
type uri;
}
}
Will result in following class hierarchy for typedefs:
SpecializedUri extends Uri
Container data will have builder with setValue(Uri value) method, which can accept also SpecializedUri, |
| Comments |
| Comment by Robert Varga [ 16/Dec/16 ] |
|
This essentially means we have to maintain type information across serialization. I think we need a typical use case where this would apply, because this has non-trivial storage cost. In order to express the requirement at yang-data-api level, each leaf's value has to also include the TypeDefinition of the type, adding one layer of encapsulation:
// T being 'String' in this case public interface ValueNode<@Nonnull T> { TypeDefinition getType(); T getValue(); } leading to public interface LeafNode<V> { ValueNode<V> getValue(); } Note that XML/JSON would require annotations to preserve this information for all data, as we cannot assume that receiver is not observing ambiguities (such as a derived type we are not aware of). For leaf and leaf-lists this will incur additional 24-32 bytes per-instance cost until Java grows support for value types (dropping it to 8-12 bytes). If we decide to pay this cost (and perform the migration), we can also extend this to NormalizedNode, where that cost is only 4-8 bytes. |
| Comment by Robert Varga [ 19/Aug/19 ] |
|
As the generated code getter will return Uri, user code wanting to forward the object towards a user which expects SpecializedUri can use an instanceof check and an explicit conversion. This issue can make that easier by exposing a utility static converter, which will integrate check/cast and conversion to SerializedUri – we already have an efficient constructor anyway. |