example of implemented Annotator interface

855 views
Skip to first unread message

dcha...@mirthcorp.com

unread,
Nov 7, 2014, 12:43:41 PM11/7/14
to jsonschema...@googlegroups.com
Here is my use case:
I want to decorate my schema with some custom properties like below

{
 
"$schema": "http://json-schema.org/draft-04/schema#",
 
"title": "Car",
 
"description": "Car",
 
"type": "object",
 
"vin":"12345"
 
"properties": {
   
"topSpeed": {
     
"type": "string",
     
"required": false
   
}
 
}
}

Notice "vin" is a custom attribute of the Car schema. I might want that to result in a custom annotation in my pojo to be something like.

@vin("12345")
public class Car { ..}

In sifting through the documentation i see that likely i need to create a class that implements org.jsonschema2pojo.Annotator.

I think what i need though is a real 'hello world' example somewhere that brings that class to life. In looking @ the interface methods I dont feel i have enough there to know what to put in the impl guts. Is there an example out there I can look at or can you provide a snippet for the above example to provide a breadcrumb.

thanks!


This message, and any documents attached hereto, may contain confidential or proprietary information intended only for the use of the addressee(s) named above or may contain information that is legally  privileged. If you are not the intended addressee, or the person responsible for delivering it to the intended addressee, you are hereby notified that reading, disseminating, distributing or copying this message is strictly prohibited. If you have received this message by mistake, please immediately notify us by replying to the message and delete the original message and any copies immediately thereafter.  Thank you for your cooperation.

Joe Littlejohn

unread,
Nov 7, 2014, 12:57:01 PM11/7/14
to jsonschema...@googlegroups.com

dcha...@mirthcorp.com

unread,
Nov 7, 2014, 1:46:51 PM11/7/14
to jsonschema...@googlegroups.com
OK. i was looking at the IT tests you had where you simply create a deprecated annotation. I am pulled that impl into my own class(CustomAnnotator.java) just to try it out and put it into a default package. I created a jar out of it. Now using the CLI tool with the -A switch I assume I can specify that 'CustomAnnotator' class name and it should work. I think I am missing something though since i just keep getting the help for the CLI returned to me. with this message 

>jsonschema2pojo -s . -t java-gen -p com.example -A CustomAnnotator
"-A": couldn't convert "CustomAnnotator" to a class
Usage: jsonschema2pojo [options]

I even opened the .bat for cli and added -cp to include my jar incase it was having issues locating the class. I expect i am just doing something silly/wrong with this.


To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-users+unsub...@googlegroups.com.

dcha...@mirthcorp.com

unread,
Nov 7, 2014, 2:04:45 PM11/7/14
to jsonschema...@googlegroups.com, dcha...@mirthcorp.com
nevermind. I was able to just put it into org.jsonscema2pojo and package it in with the core jar. probably not ideal, but for now it has me going. I would have assumed a separate jar on the classpath would have worked, so if you have a standard process for this i would be interested to know what it is. For now I will just play around with putting it into the core jar along with your existing classes.

Joe Littlejohn

unread,
Nov 7, 2014, 2:47:43 PM11/7/14
to jsonschema...@googlegroups.com
Not sure what the problem is here, but just to sanity check, did you really put the annotator in the default package?

It's not great having to open up the scripts to add -cp, we should probably add e.g. an environment variable for this.

To unsubscribe from this group and stop receiving emails from it, send an email to jsonschema2pojo-...@googlegroups.com.

Dan Chaffee

unread,
Nov 7, 2014, 4:00:52 PM11/7/14
to jsonschema...@googlegroups.com
So i created my own .jar file....called CustomAnnotator.jar i have one solitary class in there called CustomAnnotator.class which is in the default(none) package. This was just to experiment to see how i could use the CLI with custom annotators. I never was able to get that to work. What i did instead was open the jsonschema2pojo-core-0.4.5.jar packaged with the tool and put my class down in the org.jsonschema2pojo package. I of course rebuilt my class with that package name. Now when i run the CLI it works because obviously it is going to have the core jar file present. This really isnt ideal though, but it allows me to move ahead with my custom annotator coding. my question is how you _intended_ that CLI -A to work exactly. Were you thinking we would create our own .jar and put it in the classpath and it should work from there? That seems totally reasonable if so, but I was unable to get that working so i resorted to my 'hack' of just putting in the core jar for now. I really want to be able to keep my annotator separate though. Thoughts?

You received this message because you are subscribed to a topic in the Google Groups "jsonschema2pojo-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jsonschema2pojo-users/hRiwd7PZ--k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jsonschema2pojo-...@googlegroups.com.



--

Daniel Chaffee
Sr. Software Architect, NG7

NEXTGEN HEALTHCARE
Solutions for: Ambulatory, Inpatient and Community Connectivity
12301-B Riata Trace Pkwy., Suite 200, Austin, TX 78727
(321) 271-9096 [o] 
dcha...@nextgen.com or dcha...@mirthcorp.com



NOTICE: This email and its attachments, if any, may contain confidential or proprietary information and are intended solely for authorized use by the intended recipient(s) only. Any other use of this email is prohibited. If you have received this email in error, you are hereby notified that any retention, disclosure, copying, forwarding, distribution (in whole or in part and whether electronically, written and/or orally) and/or taking of any action in reliance on this email, its contents and/or any attachments thereto is strictly prohibited. If you received this email in error, please notify the sender by replying to this message and permanently delete this email, and any attachments thereto, from your system immediately.

Joe Littlejohn

unread,
Nov 7, 2014, 4:08:25 PM11/7/14
to jsonschema...@googlegroups.com

Yes exactly, I was expecting that someone would just add their extra jar to the classpath. I completely agree, your workaround of adding your class to the existing core jar is definitely not ideal.

I mentioned the package name as it stuck out as a little odd to me and I wondered if this might have been a mistake.

I'll have a play with this myself and see if I can understand what might be going wrong. Are the Maven or Gradle plugins an option for you? Modifying the classpath is a bit easier there, for obvious reasons.

Cheers

Dan Chaffee

unread,
Nov 7, 2014, 4:14:26 PM11/7/14
to jsonschema...@googlegroups.com
I have been just experimenting with a lot of things...yeah i used the maven plugin as well and that might be an option. For now I am working with the CLI to see what i can get out of it. I will keep fiddling with putting the data into my own jar and see if i can figureout where my classpath is going wrong.
Reply all
Reply to author
Forward
0 new messages