-
Notifications
You must be signed in to change notification settings - Fork 635
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
serialName
doesn't actually return @SerialName
as per docs
#2956
Comments
|
That doesn't work either, see test:
|
Lets say you want to use
at runtime i only have access to the KProperty so I can derive the Reciever type and propertyName. You would do something like:
Which is impossible as the parent descriptor only holds the @SerialName, so you get invalid index (out of bounds) so you can't reverse lookup. You could also try storing the value descriptor:
That will also fail because child descriptors are NOT unique by equality, two string descriptors are the same (understandable) Which comes back to, we either need to be able to pull SerialName from the ValueDescriptor or store the propertyName on the receiverDescriotor so can cross index descriptors. With reflection we could find the index of the property in it's parent, but needs to work on multi platform code etc... |
If you're interested how we use this, check https://github.com/MercuryTechnologies/sqkon/blob/main/library/src/commonMain/kotlin/com/mercury/sqkon/db/JsonPath.kt#L120-L133 |
If you want to make |
As a separate point, there is no reliable way to map properties (or property names) to serial elements/the serial descriptor. You could investigate and mirror the structure of the generated serializers (and library implemented serializers). However, with custom serializers there is no need for there to even be a property/element match at all. |
Thats inconsistant behaviour, if you serialize the object to json output will use the Part of the issue is that the JSON path doesn't match because the serialized enum uses the SerialName, but the descriptor doesn't give it to us... why the discrepancy ? |
Not sure what you mean here? We use descriptors at runtime to work out json paths based on KProperties and KClass's. The only info I have at runtime is the KProperty.name and the descriptor for the parent class and the field. If you are iterating across fields it's fine you don't need that, but as the SerialName gets erased and the propertyName is not kept it's really hard to find the serialName for a property name. I did look at internal implementation, unless I missed something, not sure what would help me here? |
As you say in the second paragraph this information is not available. The other point I was making is that even this poor availability is not actually applicable to custom serializers that could make up elements (from a descriptor perspective) from whole cloth or perform complex transformations. (this means that the mapping is not possible at all)
On some platforms it may be possible to use annotations with runtime retention that also have a My understanding is that you want to be able to use typesafe accessors to query into an object database. I would say that the best way to do this is a separate (or extended) compiler plugin (maybe using ksp) that generates such accessors. These accessors might even be derived from the serial descriptor (even custom ones), but it would certainly complicate matters. |
Yeah, I think might have to go down the route of kotlin compiler (don't want to rely on KSP as it would be super small compiler plugin) If you could loop back on why |
Describe the bug
descriptor.serialName
as per the docs should return the overridden@SerialName
for that field/type, but doesn't seem to respect that.To Reproduce
Unless I'm missing something, it seems impossible to get the annotated
@SerialName
from the descriptor at runtime.(Semi related, it's also impossible to find the correct element descriptor at runtime as you can't reverse lookup by elementName)
Expected behavior
Not sure if
serialName
is returning the wrong thing? But ideally I should returnnotField
as per the docs forval field
.If that is expected behavior, then the docs need updating. And we need a method to actually get that
@SerialName
.Environment
I have more examples I can share, Sqkon uses this heavily
The text was updated successfully, but these errors were encountered: