org.docx4j.services.client.JsonUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of docx4j-legacy-service Show documentation
Show all versions of docx4j-legacy-service Show documentation
Code supporting the no longer available legacy commercial PDF Converter.
package org.docx4j.services.client;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @since 8.3.1
*/
public class JsonUtil {
private static Logger log = LoggerFactory.getLogger(JsonUtil.class);
public static Map bytesToMap(byte[] json) throws Exception {
/* DocumentServices 2.0-x
* {"bookmarks":{"_Toc299924107":"68","_Toc318272803":"1"}}
*/
Map map = new HashMap();
ObjectMapper m = new ObjectMapper();
JsonNode rootNode = m.readTree(json);
JsonNode bookmarksNode = rootNode.path("bookmarks");
Iterator> bookmarksValueObj = bookmarksNode.fields();
while (bookmarksValueObj.hasNext()) {
Map.Entry entry = bookmarksValueObj.next();
if (entry.getValue()==null) {
log.warn("Null page number computed for bookmark " + entry.getKey());
}
map.put(entry.getKey(), new Integer(entry.getValue().asInt()));
}
return map;
}
}