Skip to content

Serialize output to JSON in Java #64

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 3 commits into from
Nov 3, 2016
Merged

Serialize output to JSON in Java #64

merged 3 commits into from
Nov 3, 2016

Conversation

seiflotfy
Copy link
Contributor

No description provided.

@@ -131,6 +131,8 @@ private void runMethod(Method lambdaMethod, String payload, Class cls, String ha
if (!processed) {
System.err.println(String.format("Handler %s with simple, POJO, or IO(input/output) types not found", handlerName));
}
String jsonInString = ClassTypeHelper.gson.toJson(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not 100% sure about this lib's behavior. Is it going to throw an exception or something ifthe result is not serializable? Do you want to just wrap a try catch around it?

@ucirello ucirello changed the title Serialize output to JSoN in Java Serialize output to JSON in Java Nov 2, 2016
System.out.println(jsonInString);
}
catch (Exception e) {
System.out.println("{\"error\": \"" + e + "\"}");
Copy link
Contributor

Choose a reason for hiding this comment

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

It is possible for the exception message to have " double quotes, in which case the resulting JSON will be invalid. What you want to do is replace e with gson.toJson(e.toString())?

@nikhilm nikhilm merged commit 70b6f26 into iron-io:master Nov 3, 2016
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