Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ObjectWriter.writeValueAsString() should not throw JsonProcessingException

See original GitHub issue provided a good explanation of why it is impossible for the underlying StringWriter to throw IOException.

I agree with the author, you should catch the exception and throw AssertionError if it ever occurs. Technically speaking this will never occur and it is annoying to have to catch this exception in a 1000 different pieces of code.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

cowtowncodercommented, Mar 7, 2015

I’ll make this easy here: I don’t like making special cases for particular write methods. So signature shall stay as is, and callers are free to add convenience methods, or sub-class ObjectMapper as they see fit.

raul1991commented, Mar 9, 2022

I am using Sneakythrows for it. It does put things under the carpet though 😀

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get a JsonProcessingException using Jackson
writeValueAsString (mockItem); fail("did not throw ... Trying to mock using mock(ObjectMapper.class) will invariably result in Checked ...
Read more >
ObjectWriter.writeValueAsString - Java - Tabnine
Method that can be used to serialize any Java value as a String. Functionally equivalent to calling #writeValue(Writer,Object) with ...
Read more >
Uses of Class com.fasterxml.jackson.core ...
Specialized JsonParseException that is thrown when end-of-input is reached unexpectedly, either within token being decoded, or during skipping of intervening ...
Read more >
Jackson Exceptions - Problems and Solutions - Baeldung
When we try to deserialize a JSON String to Zoo instance, it throws the JsonMappingException: Can Not Construct Instance Of:
Read more >
ObjectMapper (jackson-databind 2.9.0 API) - FasterXML
Method that will return version information stored in and read from jar that contains this class. ObjectWriter · writer(). Convenience method for constructing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found