2

My json looks like this :

{ "key1" : "aa", "key2" : "bb" }

and java class looks like this :

public class Example {

@NotBlank
@Size(min = 3, max = 5)
private String key1;

@Pattern(regexp=".+@.+\\.[a-z]+") // email
private String key2;

}

I used transform connector to convert my payload to json :

%dw 2.0
output application/java
---
payload as Object {class: "Entities/Example"}

I get this error :

"Unable to find class 'Entities/Example'

4| payload as Object {class: "Entities/Example"}
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Trace:
  at main (line: 4, column: 1), while writing Java at 
4| payload as Object {class: "Entities/Example"}

My package structure looks like this : enter image description here

HMT
  • 2,093
  • 1
  • 19
  • 51

1 Answers1

2

The problem is that your script is using a slash to separate the package from the class. It should use a period ('.') instead, as standard in Java. I would also recommend to use the standard Java convention for the packages and include organization or company.

Example:

payload as Object {class: "com.mycompany.projecta.Example"}
aled
  • 21,330
  • 3
  • 27
  • 34