"Failed to find field" and method invoking `addPropertyParameters` for an interface

292 views
Skip to first unread message

Tim Quinn

unread,
Mar 7, 2023, 7:32:01 PM3/7/23
to SnakeYAML
Hi.

We create `TypeDescription` instances for interfaces, passing both the interface class and the implementation class to the `TypeDescription` constructor. To have the parsing work the way we need, we invoke `addPropertyParameters` for several properties which is why we create the `TypeDescription` objects for these types.

Using SnakeYAML 2.0 we now see many warnings (they used to be FINE in 1.x) such as

org.yaml.snakeyaml.introspector Failed to find field for <propertyName>


I had understood--apparently incorrectly--that SnakeYAML would detect a bean property (with appropriate setter and getter methods defined on the interface) and treat such a bean property as a property for the purposes of `addPropertyParameters`. 


But it does not, and I see in the source code why: `PropertySubstitute#setTargetType)` invokes `Class#getDeclaredFields` which, of course, does not return instance fields for the bean properties because there are no instance fields on the interface.


And `setTargetType` also does not search for setter methods that would also identify the property of interest.


How can we accomplish what we want without triggering the warning messages?


Thanks.


- Tim

Tim Quinn

unread,
Mar 7, 2023, 8:08:32 PM3/7/23
to SnakeYAML
I should have mentioned that we can change the logging level for the introspector logger, and that does suppress these warnings...and, of course, others that I might want to see.

maslovalex

unread,
Mar 12, 2023, 7:40:53 AM3/12/23
to SnakeYAML
I think it was missed as part of this change


Unfortunately I have missed the fact that FINE has been changed to WARN their.... It suppose to be DEBUG and not WARNING of course.

We will try to we fix it in the next release.
Sorry for inconvenience, but  you would need to suppress this WARN for this particular logger or just ignore them for now.

-Alexander

maslovalex

unread,
Mar 12, 2023, 7:47:46 AM3/12/23
to SnakeYAML
And I hope you provide getter and setter names when create PropertySubstitude. Because PropertySubstitute does not use Introspection to discover BeansProperties.

If you can be a bit more specific with your example I might help you more.

Karthik kondapally

unread,
Mar 19, 2025, 7:02:47 PMMar 19
to SnakeYAML

Hi,

there are similar warning in the Kubernetes Java client, as discussed in this github issue.

Schema classes are automatically generated based on upstream Kubernetes JSON.


public class V1JSONSchemaProps {
      public static final String SERIALIZED_NAME_X_KUBERNETES_INT_OR_STRING = "x-kubernetes-int-or-string";
     @SerializedName(SERIALIZED_NAME_X_KUBERNETES_INT_OR_STRING)
        private Boolean xKubernetesIntOrString;
}

When we register custom TypeDescriptions 

                     TypeDescription.substituteProperty("x-kubernetes-int-or-string", field.getType(), getterMethod.getName(), setterMethod.getName());

We encounter this warning:

                      Failed to find field for io.kubernetes.client.openapi.models.V1JSONSchemaProps.x-kubernetes-int-or-string Jul 27, 2023 1:23:33 PM org.yaml.snakeyaml.internal.Logger warn

warning is obvious as V1JSONSchemaProps has field  "xKubernetesIntOrString" but not "x-kubernetes-int-or-string"

However, the actual implementation works correctly—the field "x-kubernetes-int-or-string" appears in the YAML, and since the corresponding getter and setter are properly defined, it gets mapped correctly.


Would you have any suggestions on how to suppress this warning?

Tim Quinn

unread,
Apr 8, 2025, 1:09:08 PMApr 8
to SnakeYAML
I see that this problem has been partially addressed recently in the now-=closed issue 1106. 

But there remains a WARNING-level message here: 

That logging was also originally FINE (as was the line that has been repaired recently) before they were both changed to WARNING quite some time ago.

Why was this line not also changed in the recent fix?

Reply all
Reply to author
Forward
0 new messages