Class JsonToMetadata
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,ConfigComment
,MessageEventGenerator
,Service
,StateManagedComponent
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.
-
Field Summary
Fields inherited from class com.adaptris.core.ServiceImp
log
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
void
doService
(AdaptrisMessage msg) protected void
void
prepare()
void
setMetadataPrefix
(String prefix) Specify a metadata prefix if you need one.void
Specify the behaviour when aNullNode
is encountered.Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getComments, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setComments, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
Constructor Details
-
JsonToMetadata
public JsonToMetadata()
-
-
Method Details
-
doService
- Throws:
ServiceException
-
prepare
- Throws:
CoreException
-
closeService
protected void closeService()- Specified by:
closeService
in classServiceImp
-
initService
- Specified by:
initService
in classServiceImp
- Throws:
CoreException
-
getMetadataPrefix
-
setMetadataPrefix
Specify a metadata prefix if you need one.- Parameters:
prefix
- the prefix, defaults to the empty string.
-
getNullConverter
- Returns:
- the nullConverter
-
setNullConverter
Specify the behaviour when aNullNode
is encountered.- Parameters:
nc
- the NullConverter to set, the default is effectively the string"null"
as returned byNullNode#asText()
-