[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:
Relates
relates to MDSAL-440 Reconsider TypeObject equals()/hashCo... Resolved
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,
but when serializing / deserializing data - this information that originally SpecializedUri was used is lost and returned value is only of type Uri.



 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 ]

MDSAL-440 has delivered the most critical bit of functionality of this issue, as both of those returned objects will compare as equal.

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.

Generated at Wed Feb 07 20:08:37 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.