List of usage examples for com.fasterxml.jackson.databind ObjectMapper readValue
@SuppressWarnings("unchecked") public <T> T readValue(byte[] src, JavaType valueType) throws IOException, JsonParseException, JsonMappingException
From source file:com.zxy.commons.json.JsonUtils.java
/** * json?List?/*from w w w . j a v a 2 s . c o m*/ * * @param <T> This is the type parameter * @param include include * @param listJsonString list?json * @param clazz * @return ? */ public static <T> List<T> toList(JsonInclude.Include include, String listJsonString, Class<T> clazz) { try { ObjectMapper mapper = getObjectMapper(include); return mapper.readValue(listJsonString, TypeFactory.defaultInstance().constructCollectionType(List.class, clazz)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.zxy.commons.json.JsonUtils.java
/** * json?Set?// ww w .jav a2 s.c om * * @param <T> This is the type parameter * @param include include * @param setJsonString set?json * @param clazz * @return ? */ @SuppressWarnings("PMD.LooseCoupling") public static <T> Set<T> toSet(JsonInclude.Include include, String setJsonString, Class<T> clazz) { try { ObjectMapper mapper = getObjectMapper(include); return mapper.readValue(setJsonString, TypeFactory.defaultInstance().constructCollectionType(LinkedHashSet.class, clazz)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:nl.esciencecenter.xnattool.XnatToolConfig.java
public static XnatToolConfig parseXML(String xml) throws JsonParseException, JsonMappingException, IOException { ObjectMapper xmlMapper = new XmlMapper(); XnatToolConfig value = xmlMapper.readValue(xml, XnatToolConfig.class); // check ?// ww w . j a va 2 s. co m return value; }
From source file:com.twosigma.beakerx.table.serializer.TableDisplayDeSerializer.java
@NotNull private static Object handleIndex(JsonNode n, ObjectMapper mapper, List<List<?>> values, List<String> columns, List<String> classes) throws IOException { List<String> indexName = (List<String>) mapper.readValue(n.get(INDEX_NAME).toString(), List.class); boolean standardIndex = indexName.size() == 1 && indexName.get(0).equals(INDEX); if (standardIndex) { columns.remove(0);//from w w w. j a v a 2s .co m classes.remove(0); for (List<?> v : values) { v.remove(0); } } else { columns.set(0, join(", ", indexName.stream().map(TableDisplayDeSerializer::convertNullToIndexName) .collect(Collectors.toList()))); } TableDisplay td = new TableDisplay(values, columns, classes); if (!standardIndex) { td.setHasIndex("true"); } return td; }
From source file:com.zxy.commons.json.JsonUtils.java
/** * json?Map//from w w w. j a v a 2 s. co m * * @param <K> This is the key parameter * @param <V> This is the value parameter * @param include include * @param mapJsonString map?json * @param keyClass key * @param valueClass class * @return ? */ public static <K, V> Map<K, V> toMap(JsonInclude.Include include, String mapJsonString, Class<K> keyClass, Class<V> valueClass) { // Map<K, V> map = mapper.readValue(mapString, new TypeReference<Map<K, V>>() {}); try { ObjectMapper mapper = getObjectMapper(include); return mapper.readValue(mapJsonString, TypeFactory.defaultInstance().constructMapType(Map.class, keyClass, valueClass)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.mortbay.jetty.load.generator.starter.AbstractLoadGeneratorStarter.java
protected static Resource evaluateJson(Path profilePath) throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); return objectMapper.readValue(profilePath.toFile(), Resource.class); }
From source file:org.sahli.asciidoc.confluence.publisher.client.ConfluencePublisher.java
private static ConfluencePublisherMetadata readConfig(String configPath) { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); try {//from w ww . j ava2s . co m return objectMapper.readValue(new File(configPath), ConfluencePublisherMetadata.class); } catch (IOException e) { throw new RuntimeException("Could not read metadata", e); } }
From source file:org.shareok.data.datahandlers.DataHandlersUtil.java
public static String getPublisherApiKeyByName(String publisher) throws SecurityFileDoesNotExistException, IOException { String key = ""; String securityFilePath = ShareokdataManager.getSecurityFilePath(); File securityFile = new File(securityFilePath); if (!securityFile.exists()) { throw new SecurityFileDoesNotExistException("The security file does NOT exist!"); }// w w w.java 2 s.c o m String content = new String(Files.readAllBytes(Paths.get(securityFilePath))); ObjectMapper mapper = new ObjectMapper(); RepoCredential[] credentialObjects = mapper.readValue(content, RepoCredential[].class); for (RepoCredential credentialObj : credentialObjects) { if (publisher.equals(credentialObj.getRepoName())) { key = credentialObj.getUserName(); } } return key; }
From source file:org.shareok.data.datahandlers.DataHandlersUtil.java
public static String[] getRepoCredentials(String repoName) throws SecurityFileDoesNotExistException, IOException { String[] credentials = new String[2]; String securityFilePath = ShareokdataManager.getSecurityFilePath(); File securityFile = new File(securityFilePath); if (!securityFile.exists()) { throw new SecurityFileDoesNotExistException("The security file does NOT exist!"); }// w ww . j a v a2s . co m String content = new String(Files.readAllBytes(Paths.get(securityFilePath))); ObjectMapper mapper = new ObjectMapper(); RepoCredential[] credentialObjects = mapper.readValue(content, RepoCredential[].class); for (RepoCredential credentialObj : credentialObjects) { if (repoName.equals(credentialObj.getRepoName())) { credentials[0] = credentialObj.getUserName(); credentials[1] = credentialObj.getPassword(); } } return credentials; }
From source file:com.github.hdl.tensorflow.yarn.app.ClusterSpec.java
public static Map<String, List<String>> toClusterMapFromJsonString(String clusterString) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); Map<String, List<String>> cluster = null; cluster = objectMapper.readValue(clusterString, Map.class); return cluster; }