@@ -80,12 +80,12 @@ protected <T> T doRead(Object o, Class<T> clazz) {
8080 YmlSerializer ymlSerializer = field .getAnnotation (YmlSerializer .class );
8181
8282 //filter no annotations field
83- if (noAnnotationField ( field )) {
83+ if (isNullOrEmpty ( ymlSerializer )) {
8484 continue ;
8585 }
8686
8787 //filter ignore field
88- if (ignoreField ( field )) {
88+ if (isIgnore ( ymlSerializer )) {
8989 continue ;
9090 }
9191 setValueToField (o , field , instance , ymlSerializer , clazz );
@@ -96,12 +96,12 @@ protected <T> T doRead(Object o, Class<T> clazz) {
9696 YmlSerializer ymlSerializer = method .getAnnotation (YmlSerializer .class );
9797
9898 //filter no annotations method
99- if (noAnnotationMethod ( method )) {
99+ if (isNullOrEmpty ( ymlSerializer )) {
100100 continue ;
101101 }
102102
103103 //filter ignore method
104- if (ignoreMethod ( method )) {
104+ if (isIgnore ( ymlSerializer )) {
105105 continue ;
106106 }
107107
@@ -120,9 +120,9 @@ private <T> void setValueToField(Object o, Field field, T instance, YmlSerialize
120120 Object obj = ((Map ) o ).get (getAnnotationMappingName (field .getName (), ymlSerializer ));
121121
122122 // required field
123- if (requiredField (field )) {
123+ if (requiredField (ymlSerializer )) {
124124 if (obj == null ) {
125- throw new YmlParseException (String .format ("required field - %s" , field .getName ()));
125+ throw new YmlParseException (String .format ("required field - %s , please confirm " , field .getName ()));
126126 }
127127 }
128128
@@ -170,7 +170,7 @@ protected <T> Object doWrite(Field field, T t, YmlSerializer ymlSerializer) {
170170 //annotation provider adaptor
171171 if (ymlSerializer .adaptor () != EmptyAdapter .class ) {
172172 try {
173- YmlAdaptor instance = ( YmlAdaptor ) ymlSerializer .adaptor ().newInstance ();
173+ YmlAdaptor instance = ymlSerializer .adaptor ().newInstance ();
174174 return instance .write (field .get (t ));
175175 } catch (Throwable throwable ) {
176176 throw new YmlParseException (
@@ -254,7 +254,7 @@ public <T> Object doWrite(T clazz) {
254254 // 获取 field 对应的值
255255 YmlSerializer ymlSerializer = field .getAnnotation (YmlSerializer .class );
256256
257- if (noAnnotationField ( field )) {
257+ if (isNullOrEmpty ( ymlSerializer )) {
258258 continue ;
259259 }
260260
@@ -267,7 +267,7 @@ public <T> Object doWrite(T clazz) {
267267 // 获取 field 对应的值
268268 YmlSerializer ymlSerializer = method .getAnnotation (YmlSerializer .class );
269269
270- if (noAnnotationMethod ( method )) {
270+ if (isNullOrEmpty ( ymlSerializer )) {
271271 continue ;
272272 }
273273
@@ -300,12 +300,10 @@ private String getAnnotationMappingName(String s, YmlSerializer ymlSerializer) {
300300
301301 /**
302302 * detect required field from annotation
303- *
304- * @param field field
305- * @return True or false
303+ * @param annotation
304+ * @return
306305 */
307- private Boolean requiredField (Field field ) {
308- YmlSerializer annotation = field .getAnnotation (YmlSerializer .class );
306+ private Boolean requiredField (YmlSerializer annotation ) {
309307 if (annotation == null ) {
310308 return false ;
311309 }
@@ -318,10 +316,11 @@ private Boolean requiredField(Field field) {
318316 }
319317
320318 /**
321- * filter no annotation field
319+ * detect annotation has or not
320+ * @param annotation
321+ * @return
322322 */
323- private Boolean noAnnotationField (Field field ) {
324- YmlSerializer annotation = field .getAnnotation (YmlSerializer .class );
323+ private Boolean isNullOrEmpty (YmlSerializer annotation ) {
325324 if (annotation == null ) {
326325 return true ;
327326 }
@@ -330,10 +329,11 @@ private Boolean noAnnotationField(Field field) {
330329 }
331330
332331 /**
333- * filter ignore field
332+ * filter ignore action
333+ * @param annotation
334+ * @return
334335 */
335- private Boolean ignoreField (Field field ) {
336- YmlSerializer annotation = field .getAnnotation (YmlSerializer .class );
336+ private Boolean isIgnore (YmlSerializer annotation ) {
337337 if (annotation .ignore ()) {
338338 return true ;
339339 }
@@ -342,55 +342,6 @@ private Boolean ignoreField(Field field) {
342342 }
343343
344344
345- /**
346- * filter no annotation method
347- */
348- private Boolean noAnnotationMethod (Method method ) {
349- YmlSerializer annotation = method .getAnnotation (YmlSerializer .class );
350- if (annotation == null ) {
351- return true ;
352- }
353-
354- return false ;
355- }
356-
357- /**
358- * filter ignore method
359- */
360- private Boolean ignoreMethod (Method method ) {
361- YmlSerializer annotation = method .getAnnotation (YmlSerializer .class );
362- if (annotation .ignore ()) {
363- return true ;
364- }
365-
366- return false ;
367- }
368-
369-
370- /**
371- * get all fields
372- *
373- * @return Map<name, field>
374- */
375- private Map <String , Field > allFields (Class <?> clazz ) {
376- Map <String , Field > map = new HashMap <>();
377-
378- while (true ) {
379- if (clazz == null ) {
380- break ;
381- }
382-
383- for (Field field : clazz .getDeclaredFields ()) {
384- map .put (field .getName (), field );
385- }
386-
387- clazz = clazz .getSuperclass ();
388- }
389-
390- return map ;
391- }
392-
393-
394345 private String fieldNameForSetterGetter (String fieldName ) {
395346 return Character .toUpperCase (fieldName .charAt (0 )) + fieldName .substring (1 );
396347 }
@@ -411,10 +362,6 @@ private Method getGetterMethod(Field field, Class<?> clazz) {
411362 return getMethod (field , clazz , "get" );
412363 }
413364
414- private Method getSetterMethod (Field field , Class <?> clazz ) {
415- return getMethod (field , clazz , "set" );
416- }
417-
418365 /**
419366 * get method
420367 */
0 commit comments