Skip to content

JSON difference in the key format between the client and the server #17

Description

@lynnsh

Problem

Server and client json renderers do not match. Client code (defined in client-go) expects json keys in snake_case, and the server code (defined in grafeas/grafeas) sends json keys in camelCase. Thus, server response values are ignored by the client marshaller.

Example

Field definitions:
client-go:
ShortDescription string 'json:"short_description,omitempty"'
grafeas:
ShortDescription string 'protobuf:"bytes,2,opt,name=short_description,json=shortDescription,proto3" json:"short_description,omitempty"'

What the client receives before the values are unmarshalled:
"name":"projects/grafeasclienttest/notes/grafeasattestation","shortDescription":"short","longDescription":"long","kind":"ATTESTATION","relatedUrl":[],"expirationTime":"0001-01-01T00:00:00Z","createTime":"2019-11-12T14:12:44.705616Z","updateTime":"2019-11-12T14:12:44.705616Z","relatedNoteNames":[],"attestationAuthority":{"hint":{"humanReadableName":"projects/grafeasclienttest/notes/grafeasattestation"}}

The final unmarshalled object:
Name:projects/grafeasclienttest/notes/grafeasattestation ShortDescription: LongDescription: Kind:0xc00041b0e0 RelatedUrl:[] ExpirationTime:0001-01-01 00:00:00 +0000 UTC CreateTime:0001-01-01 00:00:00 +0000 UTC UpdateTime:0001-01-01 00:00:00 +0000 UTC RelatedNoteNames:[] Vulnerability:<nil><HIGHLIGHT:END>

Potential Solution

Rename json keys in client-go models to use the camelCase, e.g. (from model_v1beta1_note.go):

// A one sentence description of this note.
ShortDescription string `json:"shortDescription,omitempty"`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions