-
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
[Feature request] Allow javaInterfaces to be passed as plugin configuration #1526
Comments
Hi I'm afraid that given case/problem is too specific to your domain, thus implementing it might be against
|
Hello! Yeah, that makes sense. Could you elaborate on the custom rule factory and rules approach? Is there a way to do this without having to re-compile the plugin and using the new custom version ? |
I think that we could take https://github.com/itzg/jsonschema2pojo-rules-bettermaps as an example (maven approach). Basically an "artifact" would have to be created/published. public class CustomObjectRule extends ObjectRule {
protected CustomObjectRule(RuleFactory ruleFactory, ParcelableHelper parcelableHelper, ReflectionHelper reflectionHelper) {
super(ruleFactory, parcelableHelper, reflectionHelper);
}
@Override
public JType apply(String nodeName, JsonNode node, JsonNode parent, JPackage _package, Schema schema) {
final JDefinedClass jClass = (JDefinedClass) super.apply(nodeName, node, parent, _package, schema);
// add custom interface's
jClass._implements(resolveType(jClass._package(), "org.jsonschema2pojo.integration.yaml.YamlTypeIT.InterfaceWithGenerics<String,Integer,Boolean>"));
return jClass;
}
} Once custom rule factory artifact is compiled/published add it as a dependency of the plugin and set the |
Thanks for the detailed answer! I'll close this issue. |
We're using this plugin to generate POJO classes from JSON schema files.
For the code that will be handling the generated classes, it would be best if they could implement an interface to ensure that the available methods are present and avoid using reflection.
I know this is already possible by adding the 'javaInterfaces' in the jsonSchema, but in this particular case the schemas are defined by the user and we would like to hide this implementation detail.
For general purpose this should likely be a map of interface -> classes that should implement it, but for our specific use case we just need the same interface to be applied to all generated classes, so it could be a
defaultJavaInterfaces
or something like that.I think this would be a simple change if it is something that you want to support. In the EnumRule and ObjectRule where we currently have
it could be changed to something like
The text was updated successfully, but these errors were encountered: