-
Notifications
You must be signed in to change notification settings - Fork 380
Feature: Allow for mapping properties containing periods #777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…el to allow for mapping properties that contain periods
Hello @JMolenkamp Excellent work!
|
Hi @DocSvartz,
|
@JMolenkamp I meant that if the constructor parameters in your cases can have names with dots, then you should pay special attention to this.
They may not mapping, even though the Properties with the same names will be mapping. |
@DocSvartz Got it. It won't be an issue in my case, the dynamically created types have a default constructor and each property both has a getter and a setter. I might take a look though. |
@DocSvartz
The latter two gave me an idea to try a different approach and keep the period joined string on the InvokerModel. |
I tried the alternative approach which turns out to be less impactful and might be preferred. Some ambiguity might be possible though, what should class Source
{
public Child A.B { get; set; }
public int A.B.C { get; set; }
}
class Child
{
public int C { get; set; }
} A risk of building dynamic types, I guess? |
This comment was marked as duplicate.
This comment was marked as duplicate.
Moved to draft in favor of #781 |
The
InvokerModel
stores the property path as a period joined string. When building the expression for a property path, this string is split on the periods, which makes it impossible to have a property name that contains periods.Obviously, this is kinda obscure, but I actually ran into this issue. It is possible to have a property name with a period when dynamically building types where pretty much all naming restrictions go out of the window, demonstrated in this test.
With this PR, instead of storing a period joined string, the path is stored as a string array. This allows for storing a property name with a period as it is not split on usage. The tests still succeed, except for
No_Errors_Thrown_With_Default_Configuration_On_Unmapped_Primitive
, which failed to begin with.If this change is considered, a skeptic review is required, even though the tests succeed. For now, this is just my initial attempt.
For some background:
Our applications frequently have to communicate with industrial devices, for which the OPC UA protocol is often used. When reading or writing some structured data, an application type requires mapping to some node hierarchy provided by the OPC UA server. The configuration for this mapping is external, such that changes in property names/types or even structure do not require a rebuild of the application. Based on the configuration, types are built dynamically and Mapster is configured to map between the application type and the dynamic type. I am not really up to date with the naming restrictions on OPC UA nodes, but usage of periods is allowed, at least in some places.