05-23-2018 05:48 AM
Dear Friends
I Get List of Nodes, then I can not deserialize json response, I get Error
com.fasterxml.jackson.databind.JsonMappingException: No suitable constructor found for type [simple type, class com.alfresco.client.api.common.representation.ResultPaging<com.alfresco.client.api.core.model.representation.NodeRepresentation>]: can not instantiate from JSON object (need to add/enable type information?)
Here is my code
HttpClient httpClient = HttpClientBuilder.create().build();
HttpGet get = new HttpGet("http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/nodes/-shared-/children");
String alfrescoUser = "admin";
String pass = "admin";
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(alfrescoUser, pass);
get.setHeader("Accept", "application/json");
get.setHeader("Content-type", "application/json");
get.setHeader(new BasicScheme().authenticate(creds, get, null));
HttpResponse response = httpClient.execute(get);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200)
{
throw new RuntimeException("Failed with HTTP error code : " + statusCode);
}
HttpEntity httpEntity = response.getEntity();
String apiOutput = EntityUtils.toString(httpEntity);
System.out.print(apiOutput);
Long total = null;
ObjectMapper om = new ObjectMapper();
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ResultPaging<NodeRepresentation> nodes = null;
nodes = om.readValue(apiOutput, new TypeReference<ResultPaging<NodeRepresentation>>() {});
Please, can you Help me?
05-24-2018 12:45 PM
What is the scenario where you would be remotely calling the Alfresco API (in other words, running from a system other than Alfresco) and then wanting to deserialize JSON objects using classes that you should not have access to (ie, Alfresco's)?
If you are in a remote system you should be deserializing JSON responses into your own POJO's, not trying to reconstruct Alfresco's.
If you are calling the remote API from within Alfresco then you shouldn't be doing that either because you've got access to the native API.
05-25-2018 01:48 AM
Thank You Jeff
I solve this problem:
I am in a remote system and I create own POJO class - Entry.class, then I extract information
List<EnrtyDTo> entryDTos= new ArrayList<EnrtyDTo>();
ObjectMapper om = new ObjectMapper();
JsonNode jsonNodeRoot = om.readTree(apiOutput);
List<JsonNode> nodes = jsonNodeRoot.findValues("entry");
for (JsonNode node : nodes) {
EnrtyDto entryDTo = om.treeToValue(node, EnrtyDto.class);
entryDTos.add(entryDTo);
}
Thank All
Explore our Alfresco products with the links below. Use labels to filter content by product module.