2424import java .beans .PropertyDescriptor ;
2525import java .beans .Transient ;
2626import java .lang .reflect .Method ;
27+ import java .util .ArrayList ;
28+ import java .util .List ;
29+ import java .util .regex .Pattern ;
30+
2731import java2typescript .jackson .module .grammar .AnyType ;
2832import java2typescript .jackson .module .grammar .FunctionType ;
2933import java2typescript .jackson .module .grammar .ClassType ;
3034import java2typescript .jackson .module .grammar .TypeDeclarationType ;
3135import java2typescript .jackson .module .grammar .VoidType ;
3236import java2typescript .jackson .module .grammar .base .AbstractType ;
3337
38+ import javax .ws .rs .DELETE ;
39+ import javax .ws .rs .GET ;
40+ import javax .ws .rs .POST ;
41+ import javax .ws .rs .PUT ;
42+
3443import com .fasterxml .jackson .databind .BeanProperty ;
3544import com .fasterxml .jackson .databind .JavaType ;
3645import com .fasterxml .jackson .databind .JsonMappingException ;
5160public class TSJsonObjectFormatVisitor extends ABaseTSJsonFormatVisitor <ClassType > implements JsonObjectFormatVisitor {
5261
5362 private Class clazz ;
63+ private List <String > blackListField = new ArrayList <String >();
5464
5565 public TSJsonObjectFormatVisitor (ABaseTSJsonFormatVisitor <?> parentHolder , String className , Class clazz , Configuration conf ) {
5666 super (parentHolder , conf );
@@ -59,7 +69,9 @@ public TSJsonObjectFormatVisitor(ABaseTSJsonFormatVisitor<?> parentHolder, Strin
5969 }
6070
6171 private void addField (String name , AbstractType fieldType ) {
62- type .getFields ().put (name , fieldType );
72+ if (!blackListField .contains (name )) {
73+ type .getFields ().put (name , fieldType );
74+ }
6375 }
6476
6577 private boolean isAccessorMethod (Method method , BeanInfo beanInfo ) {
@@ -74,6 +86,21 @@ private boolean isAccessorMethod(Method method, BeanInfo beanInfo) {
7486 return false ;
7587 }
7688
89+ private void blackListUnnecessaryFieldMethods (Method method ) {
90+ Pattern getSearcher = Pattern .compile ("^get.*" );
91+ Pattern setSearcher = Pattern .compile ("^set.*" );
92+
93+ String ignoredField = method .getName ().toLowerCase ();
94+
95+ if (getSearcher .matcher (method .getName ()).matches ()) {
96+ ignoredField = ignoredField .replaceFirst ("^get" ,"" );
97+ blackListField .add (ignoredField );
98+ } else if (setSearcher .matcher (method .getName ()).matches ()) {
99+ ignoredField = ignoredField .replaceFirst ("^set" ,"" );
100+ blackListField .add (ignoredField );
101+ }
102+ }
103+
77104 void addPublicMethods () {
78105
79106 for (Method method : this .clazz .getDeclaredMethods ()) {
@@ -83,6 +110,28 @@ void addPublicMethods() {
83110 continue ;
84111 }
85112
113+ //Don't exclude accessors
114+ if (method .getAnnotation (GET .class ) != null ) {
115+ addMethod (method );
116+ blackListUnnecessaryFieldMethods (method );
117+ continue ;
118+ }
119+ if (method .getAnnotation (POST .class ) != null ) {
120+ addMethod (method );
121+ blackListUnnecessaryFieldMethods (method );
122+ continue ;
123+ }
124+ if (method .getAnnotation (PUT .class ) != null ) {
125+ addMethod (method );
126+ blackListUnnecessaryFieldMethods (method );
127+ continue ;
128+ }
129+ if (method .getAnnotation (DELETE .class ) != null ) {
130+ addMethod (method );
131+ blackListUnnecessaryFieldMethods (method );
132+ continue ;
133+ }
134+
86135 // Exclude accessors
87136 try {
88137 BeanInfo beanInfo = Introspector .getBeanInfo (clazz );
0 commit comments