Class JsonToObject

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.LenientModeSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<adams.data.conversion.AbstractConversion>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.data.conversion.Conversion, adams.data.conversion.ConversionFromString, Serializable

    public class JsonToObject
    extends adams.data.conversion.AbstractConversionFromString
    implements adams.core.LenientModeSupporter
    Maps the JSON string to the specified class using Jackson's Databind functionality (https://github.com/FasterXML/jackson-databind).

    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
        min-user-mode: Expert
     
    -classname <adams.core.base.BaseClassname> (property: classname)
        The class to map the JSON string to.
        default: java.util.HashMap
     
    -lenient <boolean> (property: lenient)
        If enabled, unknown properties won't cause an error.
        default: false
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected adams.core.base.BaseClassname m_Classname
      the class to map the json to.
      protected boolean m_Lenient
      whether to use lenient mode.
      protected com.fasterxml.jackson.databind.ObjectMapper m_Mapper
      the mapper instance to use.
      • Fields inherited from class adams.data.conversion.AbstractConversion

        m_Input, m_Output, m_Owner, m_Stopped
      • Fields inherited from class adams.core.option.AbstractOptionHandler

        m_OptionManager
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonToObject()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      String classnameTipText()
      Returns the tip text for this property.
      void defineOptions()
      Adds options to the internal list of options.
      protected Object doConvert()
      Performs the actual conversion.
      Class generates()
      Returns the class that is generated as output.
      adams.core.base.BaseClassname getClassname()
      Returns the class to map the JSON string to.
      boolean getLenient()
      Returns whether to parse JSON in lenient mode or not.
      String getQuickInfo()
      Returns a quick info about the object, which can be displayed in the GUI.
      String globalInfo()
      Returns a string describing the object.
      String lenientTipText()
      Returns the tip text for this property.
      void setClassname​(adams.core.base.BaseClassname value)
      Sets the class to map the JSON string to.
      void setLenient​(boolean value)
      Sets whether to parse JSON in lenient mode or not.
      • Methods inherited from class adams.data.conversion.AbstractConversionFromString

        accepts
      • Methods inherited from class adams.data.conversion.AbstractConversion

        checkData, cleanUp, convert, getAdditionalInformation, getInput, getInput, getOutput, getOutput, getOwner, reset, setInput, setOwner, shallowCopy, shallowCopy, stopExecution
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.CleanUpHandler

        cleanUp
      • Methods inherited from interface adams.data.conversion.Conversion

        convert, getInput, getInput, getOutput, getOutput, getOwner, setInput, setOwner
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
      • Methods inherited from interface adams.core.Stoppable

        stopExecution
    • Field Detail

      • m_Classname

        protected adams.core.base.BaseClassname m_Classname
        the class to map the json to.
      • m_Lenient

        protected boolean m_Lenient
        whether to use lenient mode.
      • m_Mapper

        protected transient com.fasterxml.jackson.databind.ObjectMapper m_Mapper
        the mapper instance to use.
    • Constructor Detail

      • JsonToObject

        public JsonToObject()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • setClassname

        public void setClassname​(adams.core.base.BaseClassname value)
        Sets the class to map the JSON string to.
        Parameters:
        value - the classname
      • getClassname

        public adams.core.base.BaseClassname getClassname()
        Returns the class to map the JSON string to.
        Returns:
        the classname
      • classnameTipText

        public String classnameTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLenient

        public void setLenient​(boolean value)
        Sets whether to parse JSON in lenient mode or not. Latter will raise an exception if unknown properties are encountered.
        Specified by:
        setLenient in interface adams.core.LenientModeSupporter
        Parameters:
        value - true if lenient
      • getLenient

        public boolean getLenient()
        Returns whether to parse JSON in lenient mode or not. Latter will raise an exception if unknown properties are encountered.
        Specified by:
        getLenient in interface adams.core.LenientModeSupporter
        Returns:
        true if lenient
      • lenientTipText

        public String lenientTipText()
        Returns the tip text for this property.
        Specified by:
        lenientTipText in interface adams.core.LenientModeSupporter
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getQuickInfo

        public String getQuickInfo()
        Returns a quick info about the object, which can be displayed in the GUI.
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class adams.data.conversion.AbstractConversion
        Returns:
        null if no info available, otherwise short string
      • generates

        public Class generates()
        Returns the class that is generated as output.
        Specified by:
        generates in interface adams.data.conversion.Conversion
        Specified by:
        generates in class adams.data.conversion.AbstractConversion
        Returns:
        the class
      • doConvert

        protected Object doConvert()
                            throws Exception
        Performs the actual conversion.
        Specified by:
        doConvert in class adams.data.conversion.AbstractConversion
        Returns:
        the converted data
        Throws:
        Exception - if something goes wrong with the conversion