Class CPythonSerializer

java.lang.Object
nz.org.riskscape.cpython.CPythonSerializer

public class CPythonSerializer extends Object

Adds rudimentary handling of unexpected null values before we try to serialize the data (i.e. thus avoiding an NPE). The main source of an unexpected null would be the input data, e.g. we read an integer attribute from the shapefile, but the value stored is null.

Note that this does not perfectly avoid every possible NPE when serializing. It just aims to be 'good enough' to avoid falling over when the exposure-layer shapefile contains null values. Thus, we don't guarantee null-safe handling of nullable structs for example (yes, a hazard vector layer could still have null values, but users are more likely to define a type, or pick a single attribute, for the hazard-layer).

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static nz.org.riskscape.engine.types.Type
    nullSafeType(nz.org.riskscape.engine.types.Type type)
    Returns an equivalent type that will handle unexpected null values in the underlying input data.
    void
    serialize(DataOutputStream output, nz.org.riskscape.engine.types.Type type, Object value)
    Serializes the given type/value to the given output stream with additional null-safety checks.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CPythonSerializer

      public CPythonSerializer()
  • Method Details

    • serialize

      public void serialize(DataOutputStream output, nz.org.riskscape.engine.types.Type type, Object value) throws IOException

      Serializes the given type/value to the given output stream with additional null-safety checks.

      Throws:
      IOException
    • nullSafeType

      public static nz.org.riskscape.engine.types.Type nullSafeType(nz.org.riskscape.engine.types.Type type)

      Returns an equivalent type that will handle unexpected null values in the underlying input data.

      Returns:
      either the same type, or a new equivalent type that is null-safe