Ks25 Wish
Ks25 Wish

Reputation: 11

Importance of using POJO java class with KIE Server Marshalling annotations

I am able to create DMN projects in Drools 7.73 Business Central, deploy to Kie Server locally and test the REST endpoint fine without having to create any POJO java classes for custom data types. For prod, we will be packing and running kjars as microservices on cloud and consuming via REST endpoints.

I have noticed below in the documentation:

"When you use a REST endpoint of KIE Server, the best practice is to define a domain object POJO Java class, annotated with standard KIE Server marshalling annotations. For example, the following code is using a domain object Person class that is annotated properly"

https://docs.drools.org/7.73.0.Final/drools-docs/html_single/index.html#dmn-execution-rest-proc_dmn-models

  1. Could someone please explain to me why we have to create POJO Java classes in first case when we are able to execute the rules fine without creating any POJO (just declaring custom data types in DMN).

  2. I dont see DMN auto generating any POJOs based on my custom data type declarations in DMN. How does KieServer execute without POJO?

Any knowledge on this is much appreciated. Thanks

would like to understand if its needed to is POJO classes when calling via Drools service via REST endpoint

Upvotes: 1

Views: 100

Answers (1)

Mykhaylo Adamovych
Mykhaylo Adamovych

Reputation: 20966

POJO is simple data-oriented class in java. "This class can be used by any Java program as it’s not tied to any framework" (source). You do not need to do anything special for your java object classes. The point here is rather drools want simple data objects (POJOs) and it is not advisable to insert into kie session something more complex, like Spring Service for example, to make computation on it. Services are perfect candidates for global variables in drools to be used in then blocks though. Imagine to serialize to json some complicated Spring service...

Upvotes: 1

Related Questions