jsonschema2pojo icon indicating copy to clipboard operation
jsonschema2pojo copied to clipboard

Added Vert.x DataObject support

Open slinkydeveloper opened this issue 6 years ago • 9 comments

This includes:

  • Adding @DataObject annotation
  • Generating JsonObject constructor
  • Generating toJson method

Solves issue #973

Signed-off-by: slinkydeveloper [email protected]

slinkydeveloper avatar Jun 24 '19 14:06 slinkydeveloper

This looks like a good change, thanks! A few comments:

  1. Can you add the new annotation style to the docs in these places: https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html#L35 https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java#L163 https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java#L247 https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-gradle-plugin/README.md
  2. Add a new assertion to https://github.com/joelittlejohn/jsonschema2pojo/blob/master/jsonschema2pojo-core/src/test/java/org/jsonschema2pojo/AnnotatorFactoryTest.java#L34
  3. Add an integration test of some kind - anything that proves that this does what is intended. Preferably not checking for the specific annotation, but checking that the type we create is Vert.x compatible.

joelittlejohn avatar Jul 03 '19 10:07 joelittlejohn

Sorry for the delay. I've updated docs as requested. There is one thing that bothers me: If you choose to use Vertx annotator, you must always run the constructor rule that generates both constructor and toJson method. There is any specific way to override GenerationConfig? Or a condition at https://github.com/joelittlejohn/jsonschema2pojo/blob/0552b80db93214eb186e4ae45b40866cc1e7eb84/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java#L142 is fine?

slinkydeveloper avatar Aug 10 '19 08:08 slinkydeveloper

I recently added a bunch of Constructor changes as part of my copy constructor pull request. It gives a much more fine grained control to exactly which Constructors are generated, but it sounds like your configuration property has a direct requirement property on one of my new ones. That is, if the person uses yours to generate DataObject annotations they'd need to use my "includeAllPropertiesConstructor" property?

dewthefifth avatar Aug 10 '19 13:08 dewthefifth

@dewthefifth no the all properties constructor is not required by @DataObject annotation at all. The requirements for the annotation is a constructor with JsonObject as parameter and JsonObject toJson() method: https://github.com/vert-x3/vertx-codegen#dataobject-annotated-types

I was not sure where to put that code, that's why I put it in ConstructorRule

slinkydeveloper avatar Aug 10 '19 13:08 slinkydeveloper

Hmm. I think the simplest thing is just to turn this:

https://github.com/joelittlejohn/jsonschema2pojo/blob/0552b80db93214eb186e4ae45b40866cc1e7eb84/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ObjectRule.java#L142

into this:

if (ruleFactory.getGenerationConfig().isIncludeConstructors() || generationConfig.getAnnotationStyle() == AnnotationStyle.VERTX) { 

Yes?

joelittlejohn avatar Aug 13 '19 16:08 joelittlejohn

@joelittlejohn yes this is what i'm talking about :smile:

slinkydeveloper avatar Aug 13 '19 17:08 slinkydeveloper

Any progress on this one?

jklingsporn avatar Mar 06 '20 08:03 jklingsporn

@joelittlejohn where should i add an integration test?

slinkydeveloper avatar Mar 16 '20 10:03 slinkydeveloper

Any update? I'm keen to see this new feature merged!

VcamX avatar Aug 11 '20 12:08 VcamX