Class PublicStreamedFieldsProvider

Object
PublicStreamedFieldsProvider
All Implemented Interfaces:
StreamedFieldsProvider

public class PublicStreamedFieldsProvider extends Object implements StreamedFieldsProvider
Streamed fields provider which returns only public fields. Any static, private, final, transient fields are ignored.

By default fields are sorted based on their names with Comparator.naturalOrder(). Users can change the ordering of the streamed fields with PublicStreamedFieldsProvider(Function)

  • Constructor Details

    • PublicStreamedFieldsProvider

      public PublicStreamedFieldsProvider()
    • PublicStreamedFieldsProvider

      public PublicStreamedFieldsProvider(Function<Class<?>,List<String>> fieldsOrderedByNameProvider)
      Parameters:
      fieldsOrderedByNameProvider - function which returns ordered list of streamed field names for a particular class. Common implementation of this function is to read such list from the class level annotation or some special static field of that class.
  • Method Details

    • getDeclaredStreamedFields

      public List<Field> getDeclaredStreamedFields(Class<?> clazz)
      Description copied from interface: StreamedFieldsProvider
      List of all "declared" streamed fields for a given class ("declared" fields does not include fields in parent classes).

      Fields will be (de)serialized in same order as they present inside returned list.

      Note: it is not recommended to rely on the order of fields as they are returned by Class.getDeclaredFields(). Reason is because this method does not guarantee any order which would affect the (de)serialization process (for example Android 14 JVM returns fields in a different order than OpenJDK 17).

      Specified by:
      getDeclaredStreamedFields in interface StreamedFieldsProvider