Skip to content
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

Use jsonpb for JSON marshalling Statements #111

Merged
merged 1 commit into from
Jan 6, 2017
Merged

Use jsonpb for JSON marshalling Statements #111

merged 1 commit into from
Jan 6, 2017

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented Jan 6, 2017

Injects the json.Marshaller interface to the protobuf generated code, so that they can be properly marshalled to JSON using jsonpb.
It is only used for statements so far, as they are the only protobuf objects directly translated to json.
Manifests will also use the trick once they are integrated in mcnode/mcdir, in a subsequent PR.

The change is obvious in query output.
Compare:


# before
mcclient query "SELECT * FROM images.dpla LIMIT 1"
{
  "id": "4XTTM4K8sqTb7xYviJJcRDJ5W6TpQxMoJ7GtBstTALgh5wzGm:1478267497:1",
  "publisher": "4XTTM4K8sqTb7xYviJJcRDJ5W6TpQxMoJ7GtBstTALgh5wzGm",
  "namespace": "images.dpla",
  "body": {
    "Body": {
      "Simple": {
        "object": "QmeFJSTPKSEiNqebxZvYcduWH8UBmxqNq724gHEQnxV5D1",
        "refs": [
          "dpla_1ff6b36174426026847c8f8ca216ffa9"
        ],
        "deps": [
          "QmYGRQYmWC3BAtTAi88mFb7GVeFsUKGM4nm25SBUB9vfc9"
        ]
      }
    }
  },
  "timestamp": 1478267497,
  "signature": "yDhPpc/RIkW3+sHjl/cB00j3jurqMsDdb/tUyVMUfa6I4EnNiYdSqasxWTiRGtsaT2M/xX++RgRNQQ/97x8IDA=="
}

# after
mcclient query "SELECT * FROM images.dpla LIMIT 1"
{
  "id": "4XTTM4K8sqTb7xYviJJcRDJ5W6TpQxMoJ7GtBstTALgh5wzGm:1478267497:1",
  "publisher": "4XTTM4K8sqTb7xYviJJcRDJ5W6TpQxMoJ7GtBstTALgh5wzGm",
  "namespace": "images.dpla",
  "body": {
    "simple": {
      "object": "QmeFJSTPKSEiNqebxZvYcduWH8UBmxqNq724gHEQnxV5D1",
      "refs": [
        "dpla_1ff6b36174426026847c8f8ca216ffa9"
      ],
      "deps": [
        "QmYGRQYmWC3BAtTAi88mFb7GVeFsUKGM4nm25SBUB9vfc9"
      ]
    }
  },
  "timestamp": "1478267497",
  "signature": "yDhPpc/RIkW3+sHjl/cB00j3jurqMsDdb/tUyVMUfa6I4EnNiYdSqasxWTiRGtsaT2M/xX++RgRNQQ/97x8IDA=="
}

@vyzo vyzo changed the title Use jsonpb for JSON marshalling for Statements Use jsonpb for JSON marshalling Statements Jan 6, 2017
Copy link
Contributor

@yusefnapora yusefnapora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find anywhere in the alpeh / mcclient code that looks like it'll break with this change. I'm definitely in favor of the new json output 👍

@vyzo vyzo merged commit bb5b315 into master Jan 6, 2017
@vyzo vyzo deleted the vyzo-jsonpb branch January 6, 2017 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants