On Fri, 24 Sep 2021, at 10:00 AM, 'Dan Kortschak' via golang-nuts wrote:
> On Fri, 2021-09-24 at 09:55 +0100, Ian Davis wrote:
>> On Fri, 24 Sep 2021, at 9:36 AM, 'Dan Kortschak' via golang-nuts
>> wrote:
>> > On Fri, 2021-09-24 at 01:03 -0700, Brian Candler wrote:
>> > > On Friday, 24 September 2021 at 08:25:31 UTC+1 Brian Candler
>> > > wrote:
>> > > > The documentation says it prefers exact match over case-
>> > > > insensitive, but example 3 contradicts that.  It seems to be
>> > > > last-
>> > > > match that wins.
>> > > >
>> > > >
>> > >
>> > > I realise now what they mean now: if there are multiple struct
>> > > tags
>> > > defined which differ only in case, then the one which matches the
>> > > incoming field exactly is preferred.
>> > > https://play.golang.org/p/Do1dPxLOaCj
>> > >
>> >
>> > This still seems to conflict with the JSON-RPC spec:
>> >
> https://jsonrpc.org/historical/json-rpc-1-1-alt.html#service-procedure-and-parameter-names
>> >
>> > And it doesn't even appear to use the exact match in preference
>> > depending on the order of the JSON keys
>> > https://play.golang.org/p/SQyE3R-GGNn
>> >
>>
>> I think this is working as expected.  For each key in the input json
>> the unmarshaller looks for a matching struct field to hold the data
>> preferring an exact match and falling back to case insensitivity. If
>> there are multiple json keys that map to a single field then they
>> will overwrite any previously matched keys.
>>
>> This modification to your example illustrates it better:
>> https://play.golang.org/p/Ipp67LMG1Kt
>>
>> Ian
>>
>
> I agree that it can be made to work; I constructed the example that way
> it is to demonstrate the failure. Needing to guard case that way is
> pretty surprising and certainly makes it impossible to implement a
> spec-compliant JSON-RPC on top of encoding/json.
>

I was responding to your statement that it doesn't appear to use exact match in 
preference. It does, as the example I gave demonstrated. It's not about 
guarding case.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/dabd5bf2-d327-4c8c-8055-6d90be47bbb2%40www.fastmail.com.

Reply via email to