sngular / scs-multiapi-plugin

This is a Maven plugin designed to help developers automatizing the creation of code classes from YML files based on AsyncApi and OpenAPI.
http://sngular.com
Mozilla Public License 2.0
46 stars 10 forks source link

Default Constructor Generation in Payload Classes - Spring Boot #332

Open WZHMIJJ opened 6 months ago

WZHMIJJ commented 6 months ago

I have integrated the sngular/scs-multiapi-plugin Gradle plugin into my Spring Boot application to generate POJOs for AVRO schemas to be used with Pulsar. However, I encountered an issue where the generated domain objects lack a default constructor, leading to internal exceptions when using Jackson to deserialize the objects in the Pulsar listener.

I believe the plugin could be enhanced or maybe even has a posibility in one of two ways to address this issue:

  1. Include an option to generate a default constructor for payload classes.
  2. Provide support for the builder pattern when generated payload classes are used in Spring Boot.

Adding either of these features would greatly improve the compatibility of the plugin with Spring Boot Pulsar Starter.

I kindly request the addition of this feature to the plugin to improve its usability in various environments. Thank you for your consideration.

github-actions[bot] commented 6 months ago

Thank you for collaborating with the project by giving us feedback! Cheers!

malon875875 commented 6 months ago

The sngular/scs-multiapi-plugin Gradle plugin vesion used is id 'com.sngular.scs-multiapi-gradle-plugin' version '5.3.5'

jemacineiras commented 6 months ago

Hi @malon875875, @WZHMIJJ,

That is odd because we are using the pattern builder in our generated POJOS, also if you are using Lombok @Builder annotation is added.

Can we get an example of the API you are trying to build?

Cheers

WZHMIJJ commented 6 months ago

Yes, the builder is truly added, but the problem arrises that inside of Spring it does not instantiate the object. The problem is because of the domain object missing a default constructor and thus Jackson throws an internal exception.

malon875875 commented 6 months ago

Problem

Solution

tasks.withType(JavaCompile) { dependsOn insertLombokAnnotation } // end workaround



**Future Reference**
@jemacineiras It would be nice having a _useLombokModelAnnotation_ for [AsyncAPI Generator](https://github.com/sngular/scs-multiapi-plugin?tab=readme-ov-file#asyncapi-generator) in the same way that it exists for the [OpenAPI Generator](https://github.com/sngular/scs-multiapi-plugin?tab=readme-ov-file#usage)