Java

There are special use-cases that each language supports; this document pertains to Java models.

Include equals function for the class

To overwrite the equal method, use the preset JAVA_COMMON_PRESET and provide the option equal: true.

Check out this example for a live demonstration.

Include hashCode function for the class

To overwrite the hashCode method, use the preset JAVA_COMMON_PRESET and provide the option hashCode: true.

Check out this example for a live demonstration.

Change the collection type for arrays

Sometimes, we might want to render a different collection type, and instead of the default Array use as List type. To do so, provide the option collectionType: 'List'.

Check out this example for a live demonstration.

Include toString function for the class

To overwrite the toString method, use the preset JAVA_COMMON_PRESET and provide the option classToString: true.

Check out this example for a live demonstration.

Include JavaDoc for properties

To generate models containing JavaDocs from description and examples, use the JAVA_DESCRIPTION_PRESET option.

Check out this example for a live demonstration.

Include Javax validation constraint annotations for properties

In some cases, when you generate the models from JSON Schema, you may want to include javax.validation.constraint annotations.

Check out this example for a live demonstration.

Include Jakarta validation constraint annotations for properties

In some cases, when you generate the models from JSON Schema, you may want to include jakarta.validation.constraint annotations.

Check out this example for a live demonstration.

Generate serializer and deserializer functionality

The most widely used usecase for Modelina is to generate models that include serilization and deserialization functionality to convert the models into payload data. This payload data can of course be many different kinds, JSON, XML, raw binary, you name it.

As you normally only need one library to do this, we developers can never get enough with creating new stuff, therefore there might be one specific library you need or want to integrate with. Therefore there is not one specific preset that offers everything. Below is a list of all the supported serialization presets.

To and from JSON

Here are all the supported presets and the libraries they use:

Jackson annotation

To generate Java data models with Jackson annotation using JAVA_JACKSON_PRESET option.

Check out this example for a live demonstration.

External dependencies Requires com.fasterxml.jackson.annotation to work.

JSON marshaling and unmarshaling methods

Sometimes you just want to convert your class to JSON without the use of annotations such as Jackson.

Check out this example for a live demonstration.

External dependencies Requires org.json package to work.

To and from XML

Currently not supported, let everyone know you need it!

To and from binary

Currently not supported, let everyone know you need it!

Automatically create const for discriminator properties based on model name

Sometimes, we might want to immediately render the discriminator properties as constants defaulting with the model name. In this way, we do not have to define to const value our self in the schema. This is especially useful when you have a lot of models, and you want to make sure that the discriminator properties are always the same. Of course, you can always change the value in the schema, but this way you do not have to worry about it. To do so, provide the option useModelNameAsConstForDiscriminatorProperty: true.

Check out this example for a live demonstration.

Integrate Modelina into Maven

We have created an example Maven project to show you how to generate AsyncAPI payload models from your AsyncAPI file and integrate it into the build process. You can find the integration example here.