Class DataContainerSerializer

java.lang.Object
net.simplace.sim.wrapper.rest.util.DataContainerSerializer

public final class DataContainerSerializer extends Object
Converts result objects (e.g. DataContainer) into a JSON-safe structure for the REST API. Generic interim solution: via reflection, every public getter without parameters (get*, is*, to*) of the object is called and its value is put into a map. Arrays, maps and iterables are converted recursively. It could be replaced by a targeted, faster mapper for DataContainer (e.g. column-oriented: {"BiomassModule.Yield": [1.2, 3.4, ...], "CURRENT.DATE": [...]}). Known pitfalls of this generic solution: - the order of the keys is not guaranteed to be stable (reflection order) - nested SIMPLACE types (neither primitive nor collection) are only output as toString(), not resolved recursively
  • Method Details

    • toJsonSafe

      public static Object toJsonSafe(Object dataContainer)
      Converts an object into a JSON-safe map of its getter values. Getters that throw an exception are included with a placeholder text.
      Parameters:
      dataContainer - object to convert, usually a DataContainer
      Returns:
      map from property name to simplified value, or null if dataContainer is null