1
+ /*
2
+ * Copyright 2020-Present The Serverless Workflow Specification Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
package io .serverlessworkflow .generator ;
2
17
3
18
import static org .apache .commons .lang3 .StringUtils .*;
4
19
5
- import com .fasterxml .jackson .annotation .JsonUnwrapped ;
6
20
import com .fasterxml .jackson .databind .JsonNode ;
7
21
import com .fasterxml .jackson .databind .node .ArrayNode ;
8
22
import com .sun .codemodel .JClass ;
9
23
import com .sun .codemodel .JClassAlreadyExistsException ;
10
24
import com .sun .codemodel .JClassContainer ;
11
25
import com .sun .codemodel .JDefinedClass ;
26
+ import com .sun .codemodel .JExpr ;
12
27
import com .sun .codemodel .JFieldVar ;
13
28
import com .sun .codemodel .JMethod ;
14
29
import com .sun .codemodel .JMod ;
@@ -93,6 +108,10 @@ private JDefinedClass populateClass(
93
108
wrapIt (definedClass , type );
94
109
}
95
110
});
111
+ if (definedClass .constructors ().hasNext ()
112
+ && definedClass .getConstructor (new JType [0 ]) == null ) {
113
+ definedClass .constructor (JMod .PUBLIC );
114
+ }
96
115
return definedClass ;
97
116
}
98
117
@@ -112,13 +131,17 @@ private void wrapIt(JDefinedClass definedClass, JType unionType) {
112
131
JMod .PRIVATE ,
113
132
unionType ,
114
133
ruleFactory .getNameHelper ().getPropertyName (unionType .name (), null ));
115
- instanceField .annotate (JsonUnwrapped .class );
116
134
JMethod method =
117
135
definedClass .method (
118
136
JMod .PUBLIC ,
119
137
unionType ,
120
138
ruleFactory .getNameHelper ().getGetterName (unionType .name (), unionType , null ));
121
139
method .body ()._return (instanceField );
140
+ JMethod constructor = definedClass .constructor (JMod .PUBLIC );
141
+ constructor
142
+ .body ()
143
+ .assign (
144
+ JExpr ._this ().ref (instanceField ), constructor .param (unionType , instanceField .name ()));
122
145
}
123
146
124
147
private void unionType (
0 commit comments