Error in toString() when generating classes that share package with generated class called "System"

48 views
Skip to first unread message

tippe...@googlemail.com

unread,
Apr 11, 2019, 8:21:36 AM4/11/19
to jsonschema2pojo-users
I am attempting to generate Java classes from third party JSON schema, so I need to go with the names of classes.  One of the classes is called "System".  As a result, for all classes other than that class, there is an error in the `toString()` method:


@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(Status.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
...
}

The issue is in the call to `System.identityHashCode()`, because the System class is resolved to be the class in the same package, not the `java.lang.System` class.  The call within the `System` class that's generated looks like this:

sb.append(System.class.getName()).append('@').append(Integer.toHexString(java.lang.System.identityHashCode(this))).append('[');


How can I generate the code such that the fully qualified `java.lang.System` class is used for all classes?

Joe Littlejohn

unread,
Apr 11, 2019, 8:26:15 AM4/11/19
to jsonschema...@googlegroups.com
This looks like a bug. 

Feel free to raise this as a GitHub issue, and if possible please submit a pull request with a fix. If you can't see how to fix this I can fix this next week.

In the meantime, I think the only way to work around this would be to avoid using 'System' as your class name.

--
You received this message because you are subscribed to the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.
Visit this group at https://groups.google.com/group/jsonschema2pojo-users.
For more options, visit https://groups.google.com/d/optout.

tippe...@googlemail.com

unread,
Apr 11, 2019, 9:06:04 AM4/11/19
to jsonschema2pojo-users
Thanks, issue added as #969 (https://github.com/joelittlejohn/jsonschema2pojo/issues/969).  I'm not familiar with the codebase, so I'm not sure where to start.  I think the error is here:


where for some reason the class `System.class` is not given its fully qualified class name.  I don't know why the FQCN would be used in a generated class called `System`.
To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-users+unsub...@googlegroups.com.

tippe...@googlemail.com

unread,
Apr 11, 2019, 9:17:53 AM4/11/19
to jsonschema2pojo-users
Actually, this was an issue with Intellij. The generated classes were correct, I just copied them from a generated directory to a source directory, and Intellij thought it would be helpful and simplify the class as part of the copy. As a result, this actually broke the generated classes when I went to compile.

Thanks for responding, issue closed in GH.
Reply all
Reply to author
Forward
0 new messages