ObjectWriter.writeValueAsString() should not throw JsonProcessingException
See original GitHub issuehttp://jira.codehaus.org/browse/JACKSON-758?focusedCommentId=304834&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-304834 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:
- Created 9 years ago
- Comments:6 (3 by maintainers)
Top 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 java.io.StringWriterand ...
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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.I am using
Sneakythrows
for it. It does put things under the carpet though 😀