TypeConversionException

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

TypeConversionException

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,

3 Replies
Highlighted
Advanced

Re: TypeConversionException

Could you please paste your code here ?

Highlighted
Member II

Re: TypeConversionException

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();


 

Highlighted
Advanced

Re: TypeConversionException

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()