javaintellij-ideaformattingobjectmapperfasterxml

Alternate FasterXML TypeReference that formats better with default Intellij Formatter?


When you are doing a ObjectMapper.readValue on type with Generic parameters, you use this:

new ObjectMapper().readValue(someSourceValue, new TypeReference<Map<String, Object>>() {});

and format it with Intellij, you get this:

new ObjectMapper().readValue(someSourceValue, new TypeReference<Map<String, Object>>() {
});

This sticks out like a sore thumb because this is such a common operation. Has a negative impact on the readability of the code by adding all those extra line breaks.

Are there any alternatives or perhaps helper methods or other built-in ways in fasterxml that can avoid this unfortunate situation?

Goal would be to find something like this:

new ObjectMapper().readValue(someSourceValue, TypeReferenceBuilder<Map<String, Object>>.create());

Solution

  • Just tying off this question with the answer from the comments:

    Currently it's not possible.

    Feature request on YouTrack created: https://youtrack.jetbrains.com/issue/IDEA-319338/Make-an-adjustment-so-that-TypeReference-stays-on-a-single-line