Class JsonToMetadata

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Extract all root fields from a JSON document as metadata",
                      tag="service,json,metadata")
    public class JsonToMetadata
    extends ServiceImp
    Takes a JSON payload and adds every field at the root element as metadata.

    This class is included as a convenience service for you to extract all the fields of a simple JSON document as metadata. In the situation where you have a complex nested structure, then you continue use JsonPathService as normal. In the event that there are nested objects, they will be turned into strings and added as-is.

      
        {
            "category": "fiction",
            "title": "The Lord of the Rings Trilogy",
            "price": 22.99,
            "volumes": [1, 2, 3],
            "suggested": {
                "title": "The Hobbit"
            }
        }
      
      

    will give you 5 metadata keys category, title, price, volumes, suggested. The field volumes is not a string (it would be an array of integers), but it will be set as metadata as though it were (i.e the value is [1,2,3]); similarly, suggested is a nested JSON object, but it will be simply rendered as a string and added as metadata (i.e the value will be {"title:"The Hobbit"}).

    In the adapter configuration file this class is aliased as json-to-metadata which is the preferred alternative to the fully qualified classname when building your configuration.

    • Constructor Detail

      • JsonToMetadata

        public JsonToMetadata()
    • Method Detail

      • getMetadataPrefix

        public java.lang.String getMetadataPrefix()
      • setMetadataPrefix

        public void setMetadataPrefix​(java.lang.String prefix)
        Specify a metadata prefix if you need one.
        Parameters:
        prefix - the prefix, defaults to the empty string.
      • getNullConverter

        public NullConverter getNullConverter()
        Returns:
        the nullConverter
      • setNullConverter

        public void setNullConverter​(NullConverter nc)
        Specify the behaviour when a NullNode is encountered.
        Parameters:
        nc - the NullConverter to set, the default is effectively the string "null" as returned by NullNode#asText()