Repository: asyncapi/modelina (ts)

Issue:
Java generation - support for 'format' classifier
In the specification when I define my schema I can define a format e.g. datetime, email, etc.

At the moment when I generate with modelina java DTOs properties having a format defines are given a type of "Object".

Having the generated code support the api specified constraints (string = email, or string is to be interpreted as a date) is important for correctness and consistency of how an API is used.

Below is an example illustrating such an issue with date format.

![image](https://user-images.githubusercontent.com/85121176/146532868-4a188e6d-a0d6-4698-b9cb-fd52470e0dd1.png)



Pull request description:
fix: use type as a fallback if no special handling for format is provided

<!--   Thank you for your contribution. Before you submit the pull request:
1. Follow our contribution guidelines
2. Test your changes and attach their results to the pull request.
3. Update the relevant documentation.
-->

**Description**

- Add type as a fallback if no special handling for format has been provided.
- Fixes #533 

**Related issue(s)**
<!-- If you refer to a particular issue, provide its number, otherwise, remove this section.
For example, `Resolves #123`, `Fixes #43`, or `See also #33`. The `See also #33` option will not automatically close the issue after the PR merge. -->

Patch:
diff --git a/examples/generate-java-models/__snapshots__/index.spec.ts.snap b/examples/generate-java-models/__snapshots__/index.spec.ts.snap
index 4ddb7e14..5ca7f48a 100644
--- a/examples/generate-java-models/__snapshots__/index.spec.ts.snap
+++ b/examples/generate-java-models/__snapshots__/index.spec.ts.snap
@@ -3,10 +3,10 @@
 exports[`Should be able to render Java Models and should log expected output to console 1`] = `
 Array [
   "public class Root {
-  private Object email;
+  private String email;
 
-  public Object getEmail() { return this.email; }
-  public void setEmail(Object email) { this.email = email; }
+  public String getEmail() { return this.email; }
+  public void setEmail(String email) { this.email = email; }
 }",
 ]
 `;
diff --git a/examples/generate-to-files/__snapshots__/index.spec.ts.snap b/examples/generate-to-files/__snapshots__/index.spec.ts.snap
index 8449bdf6..82bf97e9 100644
--- a/examples/generate-to-files/__snapshots__/index.spec.ts.snap
+++ b/examples/generate-to-files/__snapshots__/index.spec.ts.snap
@@ -6,10 +6,10 @@ Array [
 
 
 public class Root {
-  private Object email;
+  private String email;
 
-  public Object getEmail() { return this.email; }
-  public void setEmail(Object email) { this.email = email; }
+  public String getEmail() { return this.email; }
+  public void setEmail(String email) { this.email = email; }
 }",
 ]
 `;
diff --git a/examples/java-change-collection-type/__snapshots__/index.spec.ts.snap b/examples/java-change-collection-type/__snapshots__/index.spec.ts.snap
index 2be47b3f..e51ffc02 100644
--- a/examples/java-change-collection-type/__snapshots__/index.spec.ts.snap
+++ b/examples/java-change-collection-type/__snapshots__/index.spec.ts.snap
@@ -3,10 +3,10 @@
 exports[`Should be able to render collections in Java as List and should log expected output to console 1`] = `
 Array [
   "public class Root {
-  private List<Object> email;
+  private List<String> email;
 
-  public List<Object> getEmail() { return this.email; }
-  public void setEmail(List<Object> email) { this.email = email; }
+  public List<String> getEmail() { return this.email; }
+  public void setEmail(List<String> email) { this.email = email; }
 }",
 ]
 `;
diff --git a/examples/java-generate-equals/__snapshots__/index.spec.ts.snap b/examples/java-generate-equals/__snapshots__/index.spec.ts.snap
index 20d699d7..b15f53a7 100644
--- a/examples/java-generate-equals/__snapshots__/index.spec.ts.snap
+++ b/examples/java-generate-equals/__snapshots__/index.spec.ts.snap
@@ -3,10 +3,10 @@
 exports[`Should be able to generate a model to overwrite the Equal methods and should log expected output to console 1`] = `
 Array [
   "public class Root {
-  private Object email;
+  private String email;
 
-  public Object getEmail() { return this.email; }
-  public void setEmail(Object email) { this.email = email; }
+  public String getEmail() { return this.email; }
+  public void setEmail(String email) { this.email = email; }
 
   @Override
   public boolean equals(Object o) {
diff --git a/examples/java-generate-hashcode/__snapshots__/index.spec.ts.snap b/examples/java-generate-hashcode/__snapshots__/index.spec.ts.snap
index a49b7a1f..47e05faf 100644
--- a/examples/java-generate-hashcode/__snapshots__/index.spec.ts.snap
+++ b/examples/java-generate-hashcode/__snapshots__/index.spec.ts.snap
@@ -3,10 +3,10 @@
 exports[`Should be able to generate a model to overwrite the hashCode method and should log expected output to console 1`] = `
 Array [
   "public class Root {
-  private Object email;
+  private String email;
 
-  public Object getEmail() { return this.email; }
-  public void setEmail(Object email) { this.email = email; }
+  public String getEmail() { return this.email; }
+  public void setEmail(String email) { this.email = email; }
 
   @Override
   public int hashCode() {
diff --git a/examples/java-generate-marshalling/__snapshots__/index.spec.ts.snap b/examples/java-generate-marshalling/__snapshots__/index.spec.ts.snap
index 6f1ab208..9d375330 100644
--- a/examples/java-generate-marshalling/__snapshots__/index.spec.ts.snap
+++ b/examples/java-generate-marshalling/__snapshots__/index.spec.ts.snap
@@ -3,10 +3,10 @@
 exports[`Should be able to generate ts data model with marshal und unmarshal functions and should log expected output to console 1`] = `
 Array [
   "public class Root {
-  private Object email;
+  private String email;
 
-  public Object getEmail() { return this.email; }
-  public void setEmail(Object email) { this.email = email; }
+  public String getEmail() { return this.email; }
+  public void setEmail(String email) { this.email = email; }
 
   public String marshal() {
     List<String> propList = new ArrayList();
diff --git a/examples/java-generate-tostring/__snapshots__/index.spec.ts.snap b/examples/java-generate-tostring/__snapshots__/index.spec.ts.snap
index b31b9907..07dd9ba0 100644
--- a/examples/java-generate-tostring/__snapshots__/index.spec.ts.snap
+++ b/examples/java-generate-tostring/__snapshots__/index.spec.ts.snap
@@ -3,10 +3,10 @@
 exports[`Should be able to generate a model to overwrite the toString method and should log expected output to console 1`] = `
 Array [
   "public class Root {
-  private Object email;
+  private String email;
 
-  public Object getEmail() { return this.email; }
-  public void setEmail(Object email) { this.email = email; }
+  public String getEmail() { return this.email; }
+  public void setEmail(String email) { this.email = email; }
 
   @Override
   public String toString() {
diff --git a/src/generators/java/JavaRenderer.ts b/src/generators/java/JavaRenderer.ts
index 22fdd800..8fa866a1 100644
--- a/src/generators/java/JavaRenderer.ts
+++ b/src/generators/java/JavaRenderer.ts
@@ -64,11 +64,20 @@ export abstract class JavaRenderer extends AbstractRenderer<JavaOptions, JavaGen
       kind === ModelKind.ARRAY
     ) {
       const format = model.getFromOriginalInput('format');
-      return this.toClassType(this.toJavaType(format || model.type, model));
+      return this.toClassType(this.toJavaTypeWithFormat(model.type, format, model));
     }
     return this.nameType(model.$id, model);
   }
-
+  
+  toJavaTypeWithFormat(type: string | undefined, format: string | undefined, model: CommonModel): string {
+    if (format) {
+      const returnType = this.toJavaType(format, model);
+      if (returnType !== 'Object') {
+        return returnType;
+      }
+    }
+    return this.toJavaType(type, model);
+  }
   /**
    * Returns the Java corresponding type from CommonModel type or JSON schema format
    * @param type 


Test patch:
diff --git a/test/generators/java/JavaRenderer.spec.ts b/test/generators/java/JavaRenderer.spec.ts
index 12394d0e..50dde4b3 100644
--- a/test/generators/java/JavaRenderer.spec.ts
+++ b/test/generators/java/JavaRenderer.spec.ts
@@ -38,7 +38,14 @@ describe('JavaRenderer', () => {
       expect(renderer.renderType(model)).toEqual('AnonymousSchema_1');
     });
   });
-
+  describe('toJavaTypeWithFormat()', () => {
+    test('Should be able to return type if format ist not handled', () => {
+      expect(renderer.toJavaTypeWithFormat('string', 'email', new CommonModel())).toEqual('String');
+    });
+    test('Should be able to return type for format', () => {
+      expect(renderer.toJavaTypeWithFormat('string', 'password', new CommonModel())).toEqual('String');
+    });
+  });
   describe('toJavaType()', () => {
     test('Should be able to return long', () => {
       expect(renderer.toJavaType('long', new CommonModel())).toEqual('long');