Closed thiagodpf closed 1 year ago
I had not anticipated a need to look up struct members by json tag names as the path lookup has nothing to do with json at that stage but it does seem like a nice addition. Let me take a look at what is most optimum. If what you have is performant enough would you like to create an MR for the addition or do you feel more comfortable if I make the enhancement?
I created the MR above with an adaptation of the original function from the reflect
package.
Basically what I did was open the match
function to receive a reflect.StructField
instead of just the field name as string
.
I think this adaptation performs better than the one I suggested at the beginning. If you find it interesting and want to make adjustments to better fit your rationale, feel free. I don't care about having my name as a contributor, I just want to help you not have to waste a lot of time on it. You can cancel my MR if you prefer. :satisfied: :thumbsup:
Your MR was merged and a new release has been made, v1.18.6.
I am very grateful for accepting this request, it will help me a lot and I hope it will help others too! Thank you very much!
Hello Mr Ohler! I would like to suggest an adjustment in the jp/get.go file, in the
reflectGetChild()
function.This function does not take into account the name of the element (alias) defined in the "json" tag of the struct that is passed to it.
We have structs that are populated from an
json.Unmarshal()
, but the structs have attributes whose name is a little different from the original names contained in the json. Then we would like to rely on the json attr names instead of the internal name defined in the struct. To do this, the lib would need to look for the "correct" name in the struct tags when necessary...I would like to suggest the following improvement:
So that the above change passes the following unit test:
I can't say if there is a more performant way to code this adjustment, but I kept the change simple to better exemplify the problem.
does it make sense to you?