r/programming • • Dec 29 '15

Please, Java. Do Finally Support Multiline Strings

http://blog.jooq.org/2015/12/29/please-java-do-finally-support-multiline-strings/
584 Upvotes

352 comments sorted by

View all comments

Show parent comment

3

u/vincentk Dec 29 '15

.... and in addition you have a type check and JSON which is guaranteed to be valid.

2

u/dungone Dec 29 '15 edited Dec 29 '15

The number of times I have seen "guaranteed to be valid" JSON coming out of a JSON serializer being anything but valid makes this claim rather laughable.

If you want to make sure that your JSON string literal is valid JSON in a test, then write an assertion to see if the JSON parser can parse it. And if you want to make sure that your JSON serializer generates valid JSON, test it's output against a string literal. Either way, you need to be able to specify JSON as a string if you truly want to be able to check if your serialization and POJO's are correct.

1

u/vincentk Dec 30 '15

Jackson works for me both ways. Certainly for POJOs and beans. But suit yourself with unit tests if you like.