-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
javaType with generics does not apply correct imports when "type": "object" is omitted #582
Comments
@yveszoundi Which version are you using? I could be wrong but I think this is an old bug. |
I've tried both 0.4.23 and git HEAD (as of couple days ago). The old issue #151 seems related. I think that a good test is a combination of lists and maps with generics as well as couple of random things. I'll try out couple of other versions, starting from |
@yveszoundi Have you tried using the fully qualified names of the generic types? For example, |
One other thought, I usually get this kind of functionality using
would produce an additional type for the field and its additionalProperties would be of type |
@ctrimble, I did try pretty much what I could (without coding), and that includes most of the things that could cross your mind (Fully qualified names, etc.). The goal was to recommend a contract first approach with jsonschema2pojo (existing and changing REST API). I didn't have much time to analyze and fix the issue(not really useful Maven Mojo stacktraces). |
Will look into this one. It's a regression and I'm surprised by it because we have integration tests that cover this case. Those tests are producing correct, compilable code so there's obviously an edge case here. |
So, it looks like this happens when you specify this: "aMapAppearsFewTimesWithDifferentNames": {
"javaType": "java.util.HashMap<String, Integer>"
} instead of this: "aMapAppearsFewTimesWithDifferentNames": {
"type": "object",
"javaType": "java.util.HashMap<String, Integer>"
} In the case of wanting a Java list, you can simply specify: "aMapAppearsFewTimesWithDifferentNames": {
"type": "array",
"items": {
"type": "string"
}
} |
seems this feature broken in |
@laxmikanth-demo in 1.0.0 javaType became existingJavaType |
It seems that jsonschema2pojo cannot generate complex classes (Maven plugin) with a mix of Map(generics), Collections(generics).
Issue
I have a moderately complex schema, not that complex though with Collections(generics), Maps(generics), reference to definitions. The schema itself is roughly 200 lines.
The code generation fails when attempting to perform java imports of a property defined as
"aProperty": { "javaType": "java.util.Map<String, Integer>" }
. I just get a compilation error.The maven plugin (stable or git master), generates code with an import of
java.util.Map<String, Integer>
in this case. I'd even be happy if the javaType was take as is, nevermind typing fully qualified class names.If I check against http://www.jsonschema2pojo.org/ with my full "real" example, code generation seems to work as expected. I'm not referencing any external classes at this time.
The problem is like specific to the Maven plugin, but I could be wrong...
Workaround
It consists into not using generics for collections or maps specified within
javaType
, just plain "java.util.Map".Example:
Below is a simple example of what I'm trying to achieve with simplifications.
The real code has about 35 properties, 5 references to definitions, 4 enums, 10 collection types via javatype, 6 hashmaps(generics).
The text was updated successfully, but these errors were encountered: