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

Initial commit for json serialization #24

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

vikramkadi
Copy link

No description provided.

@vikramkadi vikramkadi closed this Nov 12, 2013
@vikramkadi vikramkadi reopened this Nov 12, 2013

public String toJson() {
return JsonSerializer.getInstance().toJson(getEventName(), attributes);
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the changes here are correct. I think that instead of keeping around another structure, you should instead just convert in this function. It may require deserializing and then converting to json. @pfarner may have a similar opinion, but hopefully he'll see this.

Copy link
Author

Choose a reason for hiding this comment

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

I removed the extra structure i was using to hold attributes.

@pfarner
Copy link
Member

pfarner commented Nov 15, 2013

I'm not a JSON expert, so I'm hoping that there's a good reason to have three different JSON formats. I get why one might have typed and untyped, but how does the default one differ from the typed one?

I see that a strings have escaped quotes placed inside their values, but only in some formats. If we have a simple event containing only a string field, here are the JSON formats:

X { enc = 1; string = contents; }

default JSON (with two copies of the data, one with extra double-quotes, the other without):
{"name":"X","attributes":{"EventName":"X","string":"contents","enc":1},"typed":{"string":{"type":"string","value":""contents""},"enc":{"type":"int16","value":"1"}}}

typed (with extra double-quotes):
{"name":"X","typed":{"string":{"type":"string","value":""contents""},"enc":{"type":"int16","value":"1"}}}

untyped (no extra double-quotes):
{"name":"X","attributes":{"EventName":"X","string":"contents","enc":1}}

It seems like none of these should have the escaped double quotes within their double-quoted values.

@pfarner
Copy link
Member

pfarner commented Nov 15, 2013

It gets even weirder if I use single- or double-quote characters within the string value:

Event:
X { enc = 1; string = '"; }

default JSON:
{"name":"X","attributes":{"EventName":"X","string":"\u0027"","enc":1},"typed":{"string":{"type":"string","value":""\u0027\"""},"enc":{"type":"int16","value":"1"}}}

{"name":"X","typed":{"string":{"type":"string","value":""\u0027\"""},"enc":{"type":"int16","value":"1"}}}

{"name":"X","attributes":{"EventName":"X","string":"\u0027"","enc":1}}

The single quote is converted to unicode, and the rest of the string contents (particularly the double-quote) are getting escaped twice. I can't imagine that this is by design.

@pfarner
Copy link
Member

pfarner commented Nov 15, 2013

We should also add a "version":1, outside the attributes section, so we can change the format later.

@vikramkadi
Copy link
Author

Preston,
I have added the version attribute, Also fixed the issue with the unicode escaping of characters.
As far as escaping double quotes, i think json standard is to escape using backslash.
Also i have moved the attributes part into the Queasy plugin for lwes.

@djnym
Copy link
Member

djnym commented Feb 18, 2014

@pfarner any further comments on Vikram's changes? Otherwise, I'd like to but a bow on this request, and get it merged, and hopefully pushed to maven central.

case UINT32:
case UINT64:
case STRING:
return typeObject.toString();
Copy link
Member

Choose a reason for hiding this comment

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

Minor, but this is an unnecessary line; it could just fall through to the next case.

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.

3 participants