Class JsonToMetadata
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.core.json.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 fieldvolumes
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.
-
-
Field Summary
-
Fields inherited from class com.adaptris.core.ServiceImp
log
-
-
Constructor Summary
Constructors Constructor Description JsonToMetadata()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
void
doService(AdaptrisMessage msg)
java.lang.String
getMetadataPrefix()
NullConverter
getNullConverter()
protected void
initService()
void
prepare()
void
setMetadataPrefix(java.lang.String prefix)
Specify a metadata prefix if you need one.void
setNullConverter(NullConverter nc)
Specify the behaviour when aNullNode
is encountered.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage msg) throws ServiceException
- Throws:
ServiceException
-
prepare
public void prepare() throws CoreException
- Throws:
CoreException
-
closeService
protected void closeService()
- Specified by:
closeService
in classServiceImp
-
initService
protected void initService() throws CoreException
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
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 aNullNode
is encountered.- Parameters:
nc
- the NullConverter to set, the default is effectively the string"null"
as returned byNullNode#asText()
-
-