08-18-2020 04:18 AM
Hi,
I am trying to create a document in alfresco with metadata. taking the file and metadata info from a json file.
while creating noderef for that in webscript getting the below error,
org.alfresco.service.cmr.repository.datatype.TypeConversionException: There is no conversion registered for the value:
value class: com.fasterxml.jackson.databind.node.TextNode
to class: java.lang.String
can anyone help please.
Thanks,
08-18-2020 05:19 AM
Could you please paste your code here ?
08-18-2020 06:11 AM
Hi kaynezhang,
//getting the filename, docType and metadata as a jsonString
props.put(ContentModel.PROP_NAME, fileName);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonnode = objectMapper.readTree(metadata);
Iterator<String> fieldNames=jsonnode.fieldNames();
while(fieldNames.hasNext()) {
String paramName = fieldNames.next();
QName reqDocPropQName = QName.resolveToQName(serviceRegistry.getNamespaceService(), paramName);
props.put(reqDocPropQName, (Serializable) jsonnode.get(paramName));
}
// use the node service to create a new node
QName reqDocContentQName = QName.resolveToQName(serviceRegistry.getNamespaceService(), docType);
docNodeRef = serviceRegistry.getNodeService().createNode(descFolderNodeRef,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI,
fileName), reqDocContentQName, props) .getChildRef();
08-18-2020 10:39 PM
Alfresco property class only support some common class ,for example
String、Boolean、Character、Number、Byte、Short、Long、Float、BigDecimal、InputStream and so on.
And some alfresco specified class ,for exmple
QName、NodeRef、ChildAssociationRef、MLText and so on.
It dose not support JsonNode,so you should change it to class as mentioned above before you set it to property map
If your reqDocPropQName is long ,you can change it to long like this jsonnode.get(paramName).asLong()
If it is String you can change it to String like this jsonnode.get(paramName).toString()
Explore our Alfresco products with the links below. Use labels to filter content by product module.