Skip to content

Serialize output to JSON in Java#64

Merged
nikhilm merged 3 commits intoiron-io:masterfrom
seiflotfy:java-update
Nov 3, 2016
Merged

Serialize output to JSON in Java#64
nikhilm merged 3 commits intoiron-io:masterfrom
seiflotfy:java-update

Conversation

@seiflotfy
Copy link
Contributor

No description provided.

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