Package: lance
lancelance is a library to generate code from code.UsageLet's see how we can generate code by using lanceJavaClass GenerationHere is a json file which is fed to lance library to generate java code{"fqcn":"com.susamn.MetaClass","type":"CLASS"}generates java code as:packagecom.susamn;publicclassMetaClass{}fqcnisFully Qualified Class NameSeems pretty easy right. Let's see some involved code generation which is usable. Here is the json file for that:{"generate_path":"","classes":[{"fqcn":"com.susamn.Meta","type":"CLASS","extends":{"fqcn":"com.susamn.Parent","generic_types":["java.lang.Integer"]},"implements":[{"fqcn":"java.io.Serializable","generic_types":["java.lang.Integer"]},{"fqcn":"org.apache.Logger","generic_types":["com.susamn.Root","java.lang.String"]}],"annotations":[{"fqcn":"com.susamn.ClassLevelAnnotation1"},{"fqcn":"com.susamn.ClassLevelAnnotation2","data":{"key1":{"type":"INTEGER","value":23}}}],"attributes":[{"name":"logger","mode":"public","type":{"of":"CLASS","fqcn":"org.slf4j.api.Logger"},"accessors":true,"initialized_form":{"form":"LoggerFactory.getLogger(RiskAssessmentController.class)","imports":["org.apache.logger.api.LoggerFactory","com.susamn.RiskAssessmentController"]}},{"name":"foo","mode":"private","type":{"of":"STRING"},"accessors":true,"initialized_form":{"form":"\"Foo_Value\"","imports":[]},"annotation_level":"GETTER_ANNOTATION","annotations":[{"fqcn":"com.susamn.Annotation1","data":{"key1":{"type":"INTEGER","value":23}}},{"fqcn":"com.susamn.Annotation2","data":{"key1":{"type":"STRING","value":"String data"}}}]},{"name":"foobar","mode":"private","type":{"of":"STRING"},"accessors":true,"annotations":[{"fqcn":"com.susamn.Annotation3"},{"fqcn":"com.susamn.Annotation4","data":{"key1":{"type":"INTEGER","value":23}}}]},{"name":"bar","mode":"private","type":{"of":"LIST_STRING"},"accessors":true},{"name":"far","mode":"private","type":{"of":"LIST_INTEGER"},"accessors":true},{"name":"boo","mode":"private","type":{"of":"LIST_CLASS","fqcn":"com.susamn.Custom"},"accessors":true},{"name":"doo","mode":"private","type":{"of":"INTEGER"},"accessors":true},{"name":"dar","mode":"private","type":{"of":"FLOAT"}}],"methods":[{"name":"processRequest","mode":"public","type":{"of":"STRING"},"inputs":[{"name":"body","type":{"of":"STRING","annotations":[{"fqcn":"com.susamn.ResponseBody"}]}},{"name":"clazz","type":{"of":"LIST_CLASS","fqcn":"com.susamn.Custom2"}},{"type":{"of":"CLASS","fqcn":"org.springframework.web.mvc.HttpEntity","generic_types":["java.lang.String"]}}],"annotations":[{"fqcn":"com.susamn.Annotation11","data":{"key1":{"type":"INTEGER","value":78.10}}},{"fqcn":"com.susamn.Annotation10","data":{"key1":{"type":"INTEGER","value":12.19}}}]},{"name":"syncRequest","mode":"public","type":{"of":"CLASS","fqcn":"org.springframework.web.mvc.HttpEntity","generic_types":["GENERIC"]},"inputs":[{"name":"value","type":{"of":"STRING","annotations":[{"fqcn":"com.susamn.ResponseBody"}]}}]},{"name":"deleteRequest","mode":"public","type":{"of":"CLASS","fqcn":"org.springframework.web.mvc.HttpEntity","generic_types":["java.lang.Boolean"]},"inputs":[{"type":{"of":"STRING","annotations":[{"fqcn":"com.susamn.ResponseBody"}]}}],"body":{"form":["Map<Integer,RiskAssessment> map = new HashMap<>();","map.put(1, new RiskAssessment());"],"imports":["java.util.Map","java.util.HashMap","com.susamn.RiskAssessment"]}}]}]}this generates java code:packagecom.susamn;importcom.susamn.Annotation1;importcom.susamn.Annotation10;importcom.susamn.Annotation11;importcom.susamn.Annotation2;importcom.susamn.Annotation3;importcom.susamn.Annotation4;importcom.susamn.ClassLevelAnnotation1;importcom.susamn.ClassLevelAnnotation2;importcom.susamn.Custom;importcom.susamn.Custom2;importcom.susamn.Parent;importcom.susamn.ResponseBody;importcom.susamn.RiskAssessment;importcom.susamn.RiskAssessmentController;importcom.susamn.Root;importjava.io.Serializable;importjava.lang.Boolean;importjava.lang.Integer;importjava.lang.String;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importorg.apache.Logger;importorg.apache.logger.api.LoggerFactory;importorg.slf4j.api.Logger;importorg.springframework.web.mvc.HttpEntity;@ClassLevelAnnotation1@ClassLevelAnnotation2(key1=23)publicclassMetaextendsParent<Integer>implementsSerializable<Integer>,Logger<Root,String>{publicLoggerlogger=LoggerFactory.getLogger(RiskAssessmentController.class);privateList<String>bar;privateList<Integer>far;privateList<Custom>boo;privateintdoo;privatefloatdar;@Annotation1(key1=23)@Annotation2(key1="String data")privateStringfoo="Foo_Value";@Annotation3@Annotation4(key1=23)privateStringfoobar;publicLoggergetLogger(){returnthis.logger;}publicvoidsetLogger(Loggerlogger){this.logger=logger;}publicStringgetFoo(){returnthis.foo;}publicvoidsetFoo(Stringfoo){this.foo=foo;}publicStringgetFoobar(){returnthis.foobar;}publicvoidsetFoobar(Stringfoobar){this.foobar=foobar;}publicList<String>getBar(){returnthis.bar;}publicvoidsetBar(List<String>bar){this.bar=bar;}publicList<Integer>getFar(){returnthis.far;}publicvoidsetFar(List<Integer>far){this.far=far;}publicList<Custom>getBoo(){returnthis.boo;}publicvoidsetBoo(List<Custom>boo){this.boo=boo;}publicintgetDoo(){returnthis.doo;}publicvoidsetDoo(intdoo){this.doo=doo;}@Annotation11(key1=78.1)@Annotation10(key1=12.19)publicStringprocessRequest(@ResponseBodyStringbody,List<Custom2>clazz,HttpEntity<String>val0){}publicHttpEntity<?>syncRequest(@ResponseBodyStringvalue){}publicHttpEntity<Boolean>deleteRequest(@ResponseBodyStringval0){Map<Integer,RiskAssessment>map=newHashMap<>();map.put(1,newRiskAssessment());}}