Skip to content

Feature/json builder #11

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

Merged
merged 2 commits into from
Aug 4, 2017
Merged

Feature/json builder #11

merged 2 commits into from
Aug 4, 2017

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented May 27, 2017

This PR adds a JSON builder and parser for use with the JSON-RPC and REST-JSON marshallers and unmarshallers. It includes and depends on #14


type JsonValue = Json|Scalar|JsonArray;

// TODO move to @aws/types
Copy link

Choose a reason for hiding this comment

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

Resolve these TODO items.

private readonly utf8Decoder: Decoder
) {}

public build<T extends object>(shape: SerializationModel, input: T): string {
Copy link

Choose a reason for hiding this comment

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

Generally we should have docstrings for the public interfaces.

private format(shape: SerializationModel, input: any): JsonValue {
if (shape.type === 'structure') {
const data: Json = {};
// The validator should have ensured that this input is an object
Copy link

Choose a reason for hiding this comment

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

It seems per discussion that we mean this is the responsibility of the caller, which is not clear from this comment. Let's clarify that here.

Copy link

Choose a reason for hiding this comment

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

My reading of "The validator" was that it was elsewhere in this package.

Copy link

Choose a reason for hiding this comment

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

s/validator/caller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In line with how the responsibilities between serializers and validators are separated in other SDKs (e.g., ruby and php), the JSON builder is not expected to perform validation but just trusts that the data it has been handed fulfills the contract of the supplied serialization model. Adding a comment kind of makes this trust official, whereas other SDKs take it for granted.

However, I take your point and will throw an exception here. TypeScript definitions can mostly take the place of runtime validation, so I would expect many TS users to disable validation, and I wouldn't be surprised if we make it an opt-in rather than an opt-out part of the v3 SDK.


type JsonValue = Json|Scalar|JsonArray;

// TODO move to @aws/types
Copy link

Choose a reason for hiding this comment

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

As before, resolve these.

export class JsonParser {
constructor(private readonly base64Decoder: Decoder) {}

public parse<T extends object>(
Copy link

Choose a reason for hiding this comment

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

Docstrings for public interfaces.

return undefined;
}

return toDate(input);
Copy link

Choose a reason for hiding this comment

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

Is this date conversion method always proper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. All date formats returned by AWS services (to wit, RFC-822, ISO-8601, and unix epoch timestamps) can be handled by the toDate function.

This was referenced Jun 21, 2017
@jeskew jeskew dismissed awood45’s stale review July 13, 2017 01:42

Addressed and rebased

@jeskew
Copy link
Contributor Author

jeskew commented Jul 13, 2017

@chrisradek This has been rebased against master after merging in #35. Since the commit history's usefulness was wiped out by the rebase, I've squashed this PR down to a single commit.

@jeskew jeskew requested a review from stealthycoin August 3, 2017 00:26
Copy link
Contributor Author

@jeskew jeskew left a comment

Choose a reason for hiding this comment

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

Over the shoulder from @awood45 and @AllanFly120: fix the copy-pasta error and then :shipit:

Timestamp,
} from "@aws/types";

describe('JsonBuilder', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

s/JsonBuilder/JsonParser/

@jeskew jeskew merged commit 5cd1821 into aws:master Aug 4, 2017
@jeskew jeskew deleted the feature/json-builder branch August 4, 2017 17:17
trivikr referenced this pull request in trivikr/aws-sdk-js-v3 Dec 10, 2018
@lock
Copy link

lock bot commented Sep 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants