@ComponentProfile(summary="Extract all root fields from a JSON document as metadata", tag="service,json,metadata") public class JsonToMetadata extends ServiceImp
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.
log
CONFIRMATION_ID_KEY
Constructor and Description |
---|
JsonToMetadata() |
Modifier and Type | Method and 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 a
NullNode is encountered. |
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsConfirmation, getIsTrackingEndpoint, getLookupName, getUniqueId, init, isBranching, isConfirmation, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, rethrowServiceException, retrieveComponentState, setContinueOnFail, setIsConfirmation, setIsTrackingEndpoint, setLookupName, setUniqueId, start, stop
public void doService(AdaptrisMessage msg) throws ServiceException
ServiceException
public void prepare() throws CoreException
CoreException
protected void closeService()
closeService
in class ServiceImp
protected void initService() throws CoreException
initService
in class ServiceImp
CoreException
public java.lang.String getMetadataPrefix()
public void setMetadataPrefix(java.lang.String prefix)
prefix
- the prefix, defaults to the empty string.public NullConverter getNullConverter()
public void setNullConverter(NullConverter nc)
NullNode
is encountered.nc
- the NullConverter to set, the default is effectively the string "null"
as returned by
NullNode#asText()