cancel
Showing results for 
Search instead for 
Did you mean: 

How to map node's properties from JSON format to Map<QName, Serializable> Java object?

mbel
Star Contributor
Star Contributor

Hello,
I have a JSON representation of the properties of a node:

"properties": {
"{http://www.alfresco.org/model/content/1.0}email": "admin@alfresco.com",
"{http://www.alfresco.org/model/content/1.0}homeFolder": {
"storeRef": {
"protocol": "workspace",
"identifier": "SpacesStore"
},
"id": "b2e97ee9-1154-411e-b9b7-a7d105049b0a"
},
"{http://www.alfresco.org/model/system/1.0}cascadeTx": 163,
"{http://www.alfresco.org/model/content/1.0}lastName": "",
"{http://www.alfresco.org/model/content/1.0}preferenceValues": {
"id": 290,
"contentUrl": "store://2016/11/28/22/56/92a777ff-5dbe-461b-8d09-565d94182254.bin",
"mimetype": "text/plain",
"size": 275,
"encoding": "UTF-8",
"locale": "en_US"
},
"{http://www.alfresco.org/model/content/1.0}organizationId": "",
"{http://www.alfresco.org/model/system/1.0}node-uuid": "e8d408b8-1e7b-41c2-8722-0f7327df6919",
"{http://www.alfresco.org/model/content/1.0}name": "e8d408b8-1e7b-41c2-8722-0f7327df6919",
"{http://www.alfresco.org/model/content/1.0}sizeCurrent": 0,
"{http://www.alfresco.org/model/system/1.0}store-protocol": "workspace",
"{http://www.alfresco.org/model/system/1.0}store-identifier": "SpacesStore",
"{http://www.alfresco.org/model/system/1.0}node-dbid": 32,
"{http://www.alfresco.org/model/system/1.0}locale": "en_US",
"{http://www.alfresco.org/model/content/1.0}userName": "admin",
"{http://www.alfresco.org/model/content/1.0}homeFolderProvider": "bootstrapHomeFolderProvider",
"{http://www.alfresco.org/model/content/1.0}owner": "admin",
"{http://www.alfresco.org/model/system/1.0}cascadeCRC": 133767139,
"{http://www.alfresco.org/model/content/1.0}firstName": "Administrator"
}

And I have an issue while mapping it to Map<QName, Serializable> Java object.
I can easily parse the String to QName, but I have a problem with the Serializable interface:

11070010 Can not construct instance of java.io.Serializable, problem: abstract types either need to be mapped to concrete types, have custom deserializer, or be instantiated with additional type information at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@6a5c3c62; line: 1, column: 22376] 

Is there any way of getting the type against an QName in order to parse it automatically to that type?
Example -> "{http://www.alfresco.org/model/system/1.0}locale":  -> Locale.class
Or if someone has some other suggestions, I will be happy if you can share them.

Thank you in advance.

1 ACCEPTED ANSWER

afaust
Legendary Innovator
Legendary Innovator

Alfresco typically uses JSON object types for transporting request / response data without using types. This is due to the fact that type conversion is automatically handled in Alfresco internals when setting property values, e.g. when you set the String "en" as the value of a d:locale property then Alfresco automatically converts that to a Java locale object. You do not need to handle the conversion yourself in most cases.

If you do want to handle the conversion then you need to use the dictionary service to lookup the definition of a property by its QName, obtain the datatype definition for the property's type and use the DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, value) global utility to perform the conversion.

View answer in original post

1 REPLY 1

afaust
Legendary Innovator
Legendary Innovator

Alfresco typically uses JSON object types for transporting request / response data without using types. This is due to the fact that type conversion is automatically handled in Alfresco internals when setting property values, e.g. when you set the String "en" as the value of a d:locale property then Alfresco automatically converts that to a Java locale object. You do not need to handle the conversion yourself in most cases.

If you do want to handle the conversion then you need to use the dictionary service to lookup the definition of a property by its QName, obtain the datatype definition for the property's type and use the DefaultTypeConverter.INSTANCE.convert(dataTypeDefinition, value) global utility to perform the conversion.

Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.