[id="ref-migrate-kjar-dmn-example_{context}"]
= Example of migrating a DMN model KJAR to a {KOGITO} microservice

The following is an example of migrating a DMN model KJAR to a {KOGITO} microservice:

.Example decision service implemented using DMN model
image::kogito-microservices/example-dmn-decision-service-migrate.png[Example of a DMN decision service]

.Example DMN model using specific `ItemDefinition` structure
image::kogito-microservices/example-dmn-decision-service-migrate2.png[Example of a DMN decision service using ItemDefinition structure]

You need to define the object model (POJO) as a DTO in an existing KJAR that is developed in {BUSINESS_CENTRAL}.

.Example of an object model defined as DTO in a KJAR
[source,java]
----
package com.myspace.demo20210321;

/**
 * This class was automatically generated by the data modeler tool.
 */

public class Reservation implements java.io.Serializable {

	static final long serialVersionUID = 1L;
	@com.fasterxml.jackson.annotation.JsonFormat(shape = com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    @com.fasterxml.jackson.databind.annotation.JsonSerialize(using = com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer.class)
	private java.time.LocalDate checkin;
	@com.fasterxml.jackson.annotation.JsonFormat(shape = com.fasterxml.jackson.annotation.JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    @com.fasterxml.jackson.databind.annotation.JsonSerialize(using = com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer.class)
	private java.time.LocalDate checkout;

	private java.util.List<java.lang.String> guests;

	public Reservation() {
	}

	public java.time.LocalDate getCheckin() {
		return this.checkin;
	}

	public void setCheckin(java.time.LocalDate checkin) {
		this.checkin = checkin;
	}

	public java.time.LocalDate getCheckout() {
		return this.checkout;
	}

	public void setCheckout(java.time.LocalDate checkout) {
		this.checkout = checkout;
	}

	public java.util.List<java.lang.String> getGuests() {
		return this.guests;
	}

	public void setGuests(java.util.List<java.lang.String> guests) {
		this.guests = guests;
	}

	public Reservation(java.time.LocalDate checkin,
			java.time.LocalDate checkout,
			java.util.List<java.lang.String> guests) {
		this.checkin = checkin;
		this.checkout = checkout;
		this.guests = guests;
	}

}
----

In the previous example, the defined DTO is used in conjunction with the {KIE_SERVER} client Java API. Alternatively, you can specify the DTO in the payload, when a non-Java external application is interacting with the KJAR that is deployed on the {KIE_SERVER}.

.Example of using {KIE_SERVER} client Java API
[source,java]
----
DMNServicesClient dmnClient = kieServicesClient.getServicesClient(DMNServicesClient.class);
 DMNContext dmnContext = dmnClient.newContext();
 dmnContext.set("reservation", new com.myspace.demo20210321.Reservation(LocalDate.of(2021, 3, 1),
                                                                         LocalDate.of(2021, 3, 8),
                                                                         Arrays.asList("John", "Alice")));
 run(dmnClient, dmnContext);
----

.Example of manually specifying DTO in the payload
image::kogito-microservices/example-dmn-migrate-manual-kjar.png[Example of KJAR deployed manually]

NOTE: In the previous example, the FQCN of the object model in the REST API is used for the generic {KIE_SERVER} marshalling.
