Jackson2Rules

SUGGESTION

Simplification

View source code on GitHub

Suppression

Disable all rules by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$).* as compiler argument.

Table of contents
  1. JsonNodeOptionalInt
  2. JsonNodeOptionalString
  3. ObjectMapperValueToTree
  4. ObjectMapperConvertValueWithClass
  5. ObjectMapperConvertValueWithJavaType
  6. ObjectMapperConvertValueWithTypeReference

JsonNodeOptionalInt

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("JsonNodeOptionalInt") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$JsonNodeOptionalInt).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Optional<JsonNode>> testJsonNodeOptionalInt() {
   return ImmutableSet.of(
-      NullNode.getInstance().get(1).asOptional(),
-      NullNode.getInstance().path(2).asOptional(),
-      Optional.of(NullNode.getInstance().get(3)),
-      Optional.ofNullable(NullNode.getInstance().get(4)));
+      NullNode.getInstance().optional(1),
+      NullNode.getInstance().optional(2),
+      NullNode.getInstance().optional(3),
+      NullNode.getInstance().optional(4));
 }

JsonNodeOptionalString

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("JsonNodeOptionalString") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$JsonNodeOptionalString).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Optional<JsonNode>> testJsonNodeOptionalString() {
   return ImmutableSet.of(
-      NullNode.getInstance().get("foo").asOptional(),
-      NullNode.getInstance().path("bar").asOptional(),
-      Optional.of(NullNode.getInstance().get("baz")),
-      Optional.ofNullable(NullNode.getInstance().get("qux")));
+      NullNode.getInstance().optional("foo"),
+      NullNode.getInstance().optional("bar"),
+      NullNode.getInstance().optional("baz"),
+      NullNode.getInstance().optional("qux"));
 }

ObjectMapperValueToTree

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ObjectMapperValueToTree") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$ObjectMapperValueToTree).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<JsonNode> testObjectMapperValueToTree() throws IOException {
   return ImmutableSet.of(
-      new ObjectMapper().readTree(new ObjectMapper().writeValueAsBytes("foo")),
-      new ObjectMapper(new JsonFactory())
-          .readTree(new ObjectMapper(new JsonFactory()).writeValueAsString("bar")));
+      new ObjectMapper().valueToTree("foo"),
+      new ObjectMapper(new JsonFactory()).valueToTree("bar"));
 }

ObjectMapperConvertValueWithClass

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ObjectMapperConvertValueWithClass") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$ObjectMapperConvertValueWithClass).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Number> testObjectMapperConvertValueWithClass() throws IOException {
   return ImmutableSet.of(
-      new ObjectMapper().readValue(new ObjectMapper().writeValueAsBytes("1"), Integer.class),
-      new ObjectMapper(new JsonFactory())
-          .readValue(
-              new ObjectMapper(new JsonFactory()).writeValueAsString("2.0"), Double.class));
+      new ObjectMapper().convertValue("1", Integer.class),
+      new ObjectMapper(new JsonFactory()).convertValue("2.0", Double.class));
 }

ObjectMapperConvertValueWithJavaType

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ObjectMapperConvertValueWithJavaType") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$ObjectMapperConvertValueWithJavaType).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Number> testObjectMapperConvertValueWithJavaType() throws IOException {
   return ImmutableSet.of(
-      new ObjectMapper()
-          .readValue(
-              new ObjectMapper().writeValueAsBytes("1"),
-              SimpleType.constructUnsafe(Integer.class)),
+      new ObjectMapper().convertValue("1", SimpleType.constructUnsafe(Integer.class)),
       new ObjectMapper(new JsonFactory())
-          .readValue(
-              new ObjectMapper(new JsonFactory()).writeValueAsString("2.0"),
-              SimpleType.constructUnsafe(Double.class)));
+          .convertValue("2.0", SimpleType.constructUnsafe(Double.class)));
 }

ObjectMapperConvertValueWithTypeReference

SUGGESTION

Simplification

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("ObjectMapperConvertValueWithTypeReference") to the enclosing element.

Disable this rule by adding -XepOpt:Refaster:NamePattern=^(?!Jackson2Rules\$ObjectMapperConvertValueWithTypeReference).* as compiler argument.

Samples

Shows the difference in example code before and after the Refaster rule is applied.

 ImmutableSet<Number> testObjectMapperConvertValueWithTypeReference() throws IOException {
   return ImmutableSet.of(
-      new ObjectMapper()
-          .readValue(new ObjectMapper().writeValueAsBytes("1"), new TypeReference<Integer>() {}),
-      new ObjectMapper(new JsonFactory())
-          .readValue(
-              new ObjectMapper(new JsonFactory()).writeValueAsString("2.0"),
-              new TypeReference<Double>() {}));
+      new ObjectMapper().convertValue("1", new TypeReference<Integer>() {}),
+      new ObjectMapper(new JsonFactory()).convertValue("2.0", new TypeReference<Double>() {}));
 }

Copyright © 2017-2026 Picnic Technologies BV