spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
974 stars 595 forks source link

Empty classes are not supported in the object mapper from org.springframework.cloud.stream.binding.BindingsLifecycleController #2894

Open mgevantmakher opened 5 months ago

mgevantmakher commented 5 months ago

https://github.com/spring-cloud/spring-cloud-stream/blob/aea0e8f59110e1d3ae64affdcbdeff36a9640d60/core/spring-cloud-stream/src/main/java/org/springframework/cloud/stream/binding/BindingsLifecycleController.java#L60 Object binder should support empty classes

Proposed solution: Solution on the particular object mapper instance it would be possible to add objectMapper.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);

Issue Background of the issue: usage of 'bindings' endpoint for a 3.rd party spring cloud stream binder with an empty producer property as part of the configuration bean class inherited from a BinderSpecificPropertiesProvider throws an java.lang.IllegalArgumentException:

Exception stack: Caused by: java.lang.IllegalArgumentException: No serializer found for class <......>ProducerProperties and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.springframework.cloud.stream.binder.ExtendedProducerProperties["extension"]) (through reference chain: java.util.ArrayList[20]->org.springframework.cloud.stream.binder.AbstractMessageChannelBinder$1["extendedInfo"]) at com.fasterxml.jackson.databind.ObjectMapper._convert(ObjectMapper.java:4544) at com.fasterxml.jackson.databind.ObjectMapper.convertValue(ObjectMapper.java:4475) at org.springframework.cloud.stream.binding.BindingsLifecycleController.queryStates(BindingsLifecycleController.java:135) at org.springframework.cloud.stream.endpoint.BindingsEndpoint.queryStates(BindingsEndpoint.java:52) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) at java.base/java.lang.reflect.Method.invoke(Method.java:578)

Limitations: There is no access to the ProducerProperties class in question from a vendor binder.

Link to the binder class: https://github.com/idealo/spring-cloud-stream-binder-sqs/blob/main/src/main/java/de/idealo/spring/stream/binder/sqs/properties/SqsProducerProperties.java

sobychacko commented 5 months ago

@mgevantmakher I think this is a reasonable request. Are you open to making this change and sending a PR?

mgevantmakher commented 5 months ago

we will do a pr, thank you

sobychacko commented 5 months ago

@mgevantmakher When do you think you can work on a PR?

mgevantmakher commented 5 months ago

Our plan is to do it not later than by mid march. This issue is not abandoned.

sobychacko commented 4 months ago

@mgevantmakher This is just an FYI — we have a release coming up on 3/26. Please let us know if you are still planning to work on a PR. Otherwise, we can look into this.

mgevantmakher commented 4 months ago

We had some delays, if you would look into it it would be awesome, otherwise we have to postpone it. Thank you! @sobychacko

olegz commented 1 month ago

I don't get it. What is the value of an empty property class?

mgevantmakher commented 1 month ago

In particular use case there was no especial value for the user but the vendor of the binder choose to implement it this way.
It would be a an easy fix that enables 3. part binder usage.