2020 */
2121package org .influxdb .impl ;
2222
23+ import org .influxdb .InfluxDBMapperException ;
24+ import org .influxdb .annotation .Column ;
25+ import org .influxdb .annotation .Exclude ;
26+ import org .influxdb .annotation .Measurement ;
27+ import org .influxdb .dto .QueryResult ;
28+
2329import java .lang .reflect .Field ;
30+ import java .lang .reflect .Modifier ;
2431import java .time .Instant ;
2532import java .time .format .DateTimeFormatter ;
2633import java .time .format .DateTimeFormatterBuilder ;
3340import java .util .concurrent .ConcurrentMap ;
3441import java .util .concurrent .TimeUnit ;
3542
36- import org .influxdb .InfluxDBMapperException ;
37- import org .influxdb .annotation .Column ;
38- import org .influxdb .annotation .Measurement ;
39- import org .influxdb .dto .QueryResult ;
40-
4143/**
4244 * Main class responsible for mapping a QueryResult to a POJO.
4345 *
@@ -213,20 +215,34 @@ void cacheMeasurementClass(final Class<?>... classVarAgrs) {
213215 }
214216 ConcurrentMap <String , Field > influxColumnAndFieldMap = new ConcurrentHashMap <>();
215217
218+ Measurement measurement = clazz .getAnnotation (Measurement .class );
219+ boolean allFields = measurement != null && measurement .allFields ();
220+
216221 Class <?> c = clazz ;
217222 while (c != null ) {
218223 for (Field field : c .getDeclaredFields ()) {
219224 Column colAnnotation = field .getAnnotation (Column .class );
220- if (colAnnotation != null ) {
221- influxColumnAndFieldMap .put (colAnnotation .name (), field );
225+ if (colAnnotation == null && !(allFields
226+ && !field .isAnnotationPresent (Exclude .class ) && !Modifier .isStatic (field .getModifiers ()))) {
227+ continue ;
222228 }
229+
230+ influxColumnAndFieldMap .put (getFieldName (field , colAnnotation ), field );
223231 }
224232 c = c .getSuperclass ();
225233 }
226234 CLASS_FIELD_CACHE .putIfAbsent (clazz .getName (), influxColumnAndFieldMap );
227235 }
228236 }
229237
238+ private static String getFieldName (final Field field , final Column colAnnotation ) {
239+ if (colAnnotation != null && !colAnnotation .name ().isEmpty ()) {
240+ return colAnnotation .name ();
241+ }
242+
243+ return field .getName ();
244+ }
245+
230246 String getMeasurementName (final Class <?> clazz ) {
231247 return ((Measurement ) clazz .getAnnotation (Measurement .class )).name ();
232248 }
@@ -289,17 +305,11 @@ <T> List<T> parseSeriesAs(final QueryResult.Series series, final Class<T> clazz,
289305
290306 /**
291307 * InfluxDB client returns any number as Double.
292- * See https://github.com/influxdata/influxdb-java/issues/153#issuecomment-259681987
308+ * See <a href=" https://github.com/influxdata/influxdb-java/issues/153#issuecomment-259681987">...</a>
293309 * for more information.
294310 *
295- * @param object
296- * @param field
297- * @param value
298- * @param precision
299- * @throws IllegalArgumentException
300- * @throws IllegalAccessException
301311 */
302- <T > void setFieldValue (final T object , final Field field , final Object value , final TimeUnit precision )
312+ private static <T > void setFieldValue (final T object , final Field field , final Object value , final TimeUnit precision )
303313 throws IllegalArgumentException , IllegalAccessException {
304314 if (value == null ) {
305315 return ;
@@ -325,8 +335,8 @@ <T> void setFieldValue(final T object, final Field field, final Object value, fi
325335 }
326336 }
327337
328- <T > boolean fieldValueModified (final Class <?> fieldType , final Field field , final T object , final Object value ,
329- final TimeUnit precision )
338+ static <T > boolean fieldValueModified (final Class <?> fieldType , final Field field , final T object , final Object value ,
339+ final TimeUnit precision )
330340 throws IllegalArgumentException , IllegalAccessException {
331341 if (String .class .isAssignableFrom (fieldType )) {
332342 field .set (object , String .valueOf (value ));
@@ -351,8 +361,9 @@ <T> boolean fieldValueModified(final Class<?> fieldType, final Field field, fina
351361 return false ;
352362 }
353363
354- <T > boolean fieldValueForPrimitivesModified (final Class <?> fieldType , final Field field , final T object ,
355- final Object value ) throws IllegalArgumentException , IllegalAccessException {
364+ static <T > boolean fieldValueForPrimitivesModified (final Class <?> fieldType , final Field field , final T object ,
365+ final Object value )
366+ throws IllegalArgumentException , IllegalAccessException {
356367 if (double .class .isAssignableFrom (fieldType )) {
357368 field .setDouble (object , ((Double ) value ).doubleValue ());
358369 return true ;
@@ -372,8 +383,9 @@ <T> boolean fieldValueForPrimitivesModified(final Class<?> fieldType, final Fiel
372383 return false ;
373384 }
374385
375- <T > boolean fieldValueForPrimitiveWrappersModified (final Class <?> fieldType , final Field field , final T object ,
376- final Object value ) throws IllegalArgumentException , IllegalAccessException {
386+ static <T > boolean fieldValueForPrimitiveWrappersModified (final Class <?> fieldType , final Field field , final T object ,
387+ final Object value )
388+ throws IllegalArgumentException , IllegalAccessException {
377389 if (Double .class .isAssignableFrom (fieldType )) {
378390 field .set (object , value );
379391 return true ;
@@ -393,7 +405,7 @@ <T> boolean fieldValueForPrimitiveWrappersModified(final Class<?> fieldType, fin
393405 return false ;
394406 }
395407
396- private Long toMillis (final long value , final TimeUnit precision ) {
408+ private static Long toMillis (final long value , final TimeUnit precision ) {
397409
398410 return TimeUnit .MILLISECONDS .convert (value , precision );
399411 }
0 commit comments