- edited description
WARNING: Failed to find field for
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
- YAML keys can contain characters like hyphens (
-
), but Java field names cannot. -
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 useTypeDescription.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 offull-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)…..
- When we register a custom
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)
-
reporter -
- changed status to open
I think at least one of the warnings is actually logged in a wrong Level, just like I have described in : https://groups.google.com/g/snakeyaml-core/c/JOzKbNLorHs/m/IRvH08UoBQAJ
But it has never been fixed :(
I'll review some those level we use and hopefully we can get it released soon.
-
fix: add debug level to internal logger
Log 'Failed to find field...' in PropertySubstitute as DEBUG message instead of WARN.
see
#1106→ <<cset 0c5b3e513a8a>>
-
It will be delivered in version 2.5:
-
-
assigned issue to
-
assigned issue to
-
@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.
-
reporter @Alexander Maslov @Andrey Somov Thanks for fixing this.
-
- changed status to resolved
- Log in to comment