WARNING: Failed to find field for

Issue #1106 resolved
Karthik Kondapally created an issue

summary of the warning that was seen in kuberenetes java client because of snakeyaml.

In SnakeYAML, when a data object (or POJO) has a field name in Java that differs from the key in YAML, but the field is annotated (e.g., with @SerializedName, @JsonProperty, or @JsonbProperty) with correct value, serialization and deserialization works correctly when we map annotated value(i.e actual key in yaml) to setter and getter using TypeDescription. substituteProperty()

However, a warning is logged when registering the field using a TypeDescription.

  • WARNING: Failed to find field for

  1. YAML keys can contain characters like hyphens (-), but Java field names cannot.
  2. Example:

    ``` public class Person { @SerializedName("full-name") private String name; }

    ```

    so we use Typedescription along with constructor to map the key and related setters and getter.

    Typedescription.substituteProperty( "full-name", field.getType(), getterMethod.getName(), setterMethod.getName());

    SnakeYAML Field Lookup Issue:

    • When we register a custom TypeDescription and use TypeDescription.substituteProperty("full-name", field.getType(), getterMethod.getName(), setterMethod.getName());, SnakeYAML tries to find a field named "full-name" in Java.
    • Since field name is name instead of full-name, SnakeYAML logs a warning

      ``` Mar 20, 2025 7:50:13 PM org.yaml.snakeyaml.internal.Logger warn WARNING: Failed to find field for SnakeYamlTest$PersonGson.full-name Mar 20, 2025 7:50:13 PM org.yaml.snakeyaml.internal.Logger warn WARNING: Failed to find field for SnakeYamlTest$PersonJackson.full-name Mar 20, 2025 7:50:13 PM org.yaml.snakeyaml.internal.Logger warn WARNING: Failed to find field for SnakeYamlTest$PersonJsonb.full-name

      ``` * However, since the getter and setter exist, the mapping still works correctly despite the warning.

    This warning comes for any data serialization library like gson , jackson, where annotated value(yaml key name) is different than the actual field name in data object

    Here is demo code where we can see warning for different data serialization libraries(gson, jackson, jakarta)…..

Throwing out initial ideas, to get it started.

One possible solution would be to the let the user pass annotated value also, i.e. in PropertySubstitute add one more value String annotatedValue

  public PropertySubstitute(String name, String annotatedValue, Class<?> type, String readMethod, String writeMethod,
      Class<?>... params) {
    super(name, type);
    this.annotatedValue = annotatedValue;
    this.readMethod = readMethod;
    this.writeMethod = writeMethod;
    setActualTypeArguments(params);
    this.filler = false;
  }

  public PropertySubstitute(String name, Class<?> type, String readMethod, String writeMethod,
          Class<?>... params) {
        this(name, null, type, null, null, params);
      }

  public PropertySubstitute(String name, Class<?> type, Class<?>... params) {
    this(name, null, type, null, null, params);
  }

Then based on annotatedValue decide to either match field name or value in annotation of field in TypeDescription.setTargetType()

Comments (8)

  1. Andrey Somov

    @Karthik Kondapally can you wait for the summer release?

    (you can use the source to build and use your own release)

    If it is very urgent and critical, we may try to release it earlier.

  2. Log in to comment