Class FileDeserializer<Data>

Type Parameters:
Data - The data type to deserialize the file to
All Implemented Interfaces:
Destructible, MutableObjectProperty<Data>, MutableProperty<Data>, ObservableObjectProperty<Data>, ObservableProperty<Data>, SimpleObservableProperty<Data>, Property<Data>, Functor<Data>
Direct Known Subclasses:
HotFileDeserializer

public class FileDeserializer<Data> extends SimpleObservableObjectProperty<Data>
Deserializes data from a given JSON file.
  • Field Details

    • path

      protected final String path
    • alwaysCreateData

      protected boolean alwaysCreateData
    • ALWAYS_CREATE_DATA_DEFAULT

      public static final boolean ALWAYS_CREATE_DATA_DEFAULT
      See Also:
  • Constructor Details

    • FileDeserializer

      public FileDeserializer(String path, Class<Data> dataType)
    • FileDeserializer

      public FileDeserializer(String path, Class<Data> dataType, boolean alwaysCreateData)
  • Method Details

    • setAlwaysCreateData

      public void setAlwaysCreateData(boolean alwaysCreateData)
    • deserialize

      public Data deserialize()
      Deserializes the data from the file and stores it as the value of this property.
      Returns:
      The deserialized data.
    • createFallbackData

      protected Data createFallbackData()
    • createInputStream

      protected InputStream createInputStream()
      Creates an input stream from the file.
      Returns:
      The input stream.
    • createProperty

      @Contract("_ -> new") public <T> DeserializedObjectProperty<T> createProperty(DeserializedObjectProperty.ValueFactory<Data,T> valueFactory)
      Creates a property whose value is retrieved from the deserialized data.
      Type Parameters:
      T - The type of value of the property
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      Returns:
      The new property.
    • createProperty

      @Contract("_, _ -> new") public <T> DeserializedObjectProperty<T> createProperty(DeserializedObjectProperty.ValueFactory<Data,T> valueFactory, T fallbackValue)
      Creates a property whose value is retrieved from the deserialized data.
      Type Parameters:
      T - The type of value of the property
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      fallbackValue - Fallback value to use in case the deserialized data is empty or incomplete.
      Returns:
      The new property.
    • createIntProperty

      @Contract("_ -> new") public DeserializedIntProperty createIntProperty(DeserializedIntProperty.ValueFactory<Data> valueFactory)
      Creates an int property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      Returns:
      The new property.
    • createIntProperty

      @Contract("_, _ -> new") public DeserializedIntProperty createIntProperty(DeserializedIntProperty.ValueFactory<Data> valueFactory, int fallbackValue)
      Creates an int property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      fallbackValue - Fallback value to use in case the deserialized data is empty.
      Returns:
      The new property.
    • createFloatProperty

      @Contract("_ -> new") public DeserializedFloatProperty createFloatProperty(DeserializedFloatProperty.ValueFactory<Data> valueFactory)
      Creates a float property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      Returns:
      The new property.
    • createFloatProperty

      @Contract("_, _ -> new") public DeserializedFloatProperty createFloatProperty(DeserializedFloatProperty.ValueFactory<Data> valueFactory, float fallbackValue)
      Creates a float property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      fallbackValue - Fallback value to use in case the deserialized data is empty.
      Returns:
      The new property.
    • createBooleanProperty

      @Contract("_ -> new") public DeserializedBooleanProperty createBooleanProperty(DeserializedBooleanProperty.ValueFactory<Data> valueFactory)
      Creates a boolean property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      Returns:
      The new property.
    • createBooleanProperty

      @Contract("_, _ -> new") public DeserializedBooleanProperty createBooleanProperty(DeserializedBooleanProperty.ValueFactory<Data> valueFactory, boolean fallbackValue)
      Creates a boolean property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      fallbackValue - Fallback value to use in case the deserialized data is empty.
      Returns:
      The new property.
    • createStringProperty

      @Contract("_ -> new") public DeserializedStringProperty createStringProperty(DeserializedObjectProperty.ValueFactory<Data,String> valueFactory)
      Creates a string property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      Returns:
      The new property.
    • createStringProperty

      @Contract("_, _ -> new") public DeserializedStringProperty createStringProperty(DeserializedObjectProperty.ValueFactory<Data,String> valueFactory, String fallbackValue)
      Creates a string property whose value is retrieved from the deserialized data.
      Parameters:
      valueFactory - The method used to retrieve the value from the deserialized file.
      fallbackValue - Fallback value to use in case the deserialized data is empty or incomplete.
      Returns:
      The new property.
    • addDeserializers

      public static void addDeserializers(ValueDeserializer<?>... deserializers)
      Adds value deserializers to the object mapper using a FileDeserializerModule.
      Parameters:
      deserializers - The deserializers to add
    • resetFeatureStates

      public static void resetFeatureStates()
      Resets the states of features of the object mapper to their default state.
    • setFailOnNullForPrimitives

      public static void setFailOnNullForPrimitives(boolean state)
      Sets the state of DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES for the object mapper.
      Parameters:
      state - Whether to enable or disable the feature
    • setFailOnUnknowProperties

      public static void setFailOnUnknowProperties(boolean state)
      Sets the state of DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES for the object mapper.
      Parameters:
      state - Whether to enable or disable the feature
    • setFailOnInvalidSubtype

      public static void setFailOnInvalidSubtype(boolean state)
      Sets the state of DeserializationFeature.FAIL_ON_INVALID_SUBTYPE for the object mapper.
      Parameters:
      state - Whether to enable or disable the feature
    • setFeatureState

      public static void setFeatureState(com.fasterxml.jackson.databind.DeserializationFeature feature, boolean state)
      Enables or disables a deserialization feature of the object mapper.
      Parameters:
      feature - The feature to enable or disable
      state - Whether to enable or disable the feature