@Override public BaseException unmarshall(JsonNode jsonContent) throws Exception { return MAPPER.treeToValue(jsonContent, exceptionClass); }
@Override public AmazonServiceException unmarshall(JsonNode jsonContent) throws Exception { return MAPPER.treeToValue(jsonContent, exceptionClass); }
public static <T> T read(JsonNode json, Class<T> type) { try { return OBJECT_MAPPER.treeToValue(json, type); } catch (IOException e) { throw new RuntimeException(e); } }
public static <T> T parseObject(String body, String field, Class<T> clazz) { ObjectMapper mapper = new ObjectMapper(); JsonNode node = null; try { node = mapper.readTree(body); node = node.get(field); return mapper.treeToValue(node, clazz); } catch (IOException e) { e.printStackTrace(); } return null; }
private Optional<CategoriesTrendItem> parseItem(final Path historyFile, final ObjectMapper mapper, final JsonNode child) { try { return Optional.ofNullable(mapper.treeToValue(child, CategoriesTrendItem.class)); } catch (JsonProcessingException e) { LOGGER.warn("Could not read {}", historyFile, e); return Optional.empty(); } }
private Optional<RetryTrendItem> parseItem(final Path historyFile, final ObjectMapper mapper, final JsonNode child) { try { return Optional.ofNullable(mapper.treeToValue(child, RetryTrendItem.class)); } catch (JsonProcessingException e) { LOGGER.warn("Could not read {}", historyFile, e); return Optional.empty(); } }
private Optional<DurationTrendItem> parseItem(final Path historyFile, final ObjectMapper mapper, final JsonNode child) { try { return Optional.ofNullable(mapper.treeToValue(child, DurationTrendItem.class)); } catch (JsonProcessingException e) { LOGGER.warn("Could not read {}", historyFile, e); return Optional.empty(); } }
@JsonSetter("user") public void setUser(JsonNode jsonNode) { if (jsonNode.isObject()) { try { this.user = new ObjectMapper().treeToValue(jsonNode, User.class); } catch (JsonProcessingException e) { logger.error("Error deserializing json: ", e); } } else if (jsonNode.isTextual()) { this.userId = jsonNode.asText(); } }
@JsonSetter("channel") public void setChannel(JsonNode jsonNode) { if (jsonNode.isObject()) { try { this.channel = new ObjectMapper().treeToValue(jsonNode, Channel.class); } catch (JsonProcessingException e) { logger.error("Error deserializing json: ", e); } } else if (jsonNode.isTextual()) { this.channelId = jsonNode.asText(); } }
/** * Uses jackson to load json configuration from a File into a full object * tree representation of that json. */ public JmxProcess parseProcess(File file) throws IOException { String fileName = file.getName(); ObjectMapper mapper = fileName.endsWith(".yml") || fileName.endsWith(".yaml") ? yamlMapper : jsonMapper; JsonNode jsonNode = mapper.readTree(file); JmxProcess jmx = mapper.treeToValue(jsonNode, JmxProcess.class); jmx.setName(fileName); return jmx; } }
@JsonSetter("file") public void setFile(JsonNode jsonNode) { if (jsonNode.isObject()) { try { this.file = new ObjectMapper().treeToValue(jsonNode, File.class); } catch (JsonProcessingException e) { logger.error("Error deserializing json: ", e); } } else if (jsonNode.isTextual()) { this.fileId = jsonNode.asText(); } }
@JsonSetter("comment") public void setComment(JsonNode jsonNode) { if (jsonNode.isObject()) { try { this.comment = new ObjectMapper().treeToValue(jsonNode, Comment.class); } catch (JsonProcessingException e) { logger.error("Error deserializing json: ", e); } } else if (jsonNode.isTextual()) { this.commentId = jsonNode.asText(); } }
private Optional<HistoryTrendItem> parseItem(final Path historyFile, final ObjectMapper mapper, final JsonNode child) { try { if (Objects.nonNull(child.get("total"))) { final Statistic statistic = mapper.treeToValue(child, Statistic.class); return Optional.of(new HistoryTrendItem().setStatistic(statistic)); } return Optional.ofNullable(mapper.treeToValue(child, HistoryTrendItem.class)); } catch (JsonProcessingException e) { LOGGER.warn("Could not read {}", historyFile, e); return Optional.empty(); } }
@Override public CoinMarketCapArrayData<CoinMarketCapTicker> deserialize( JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException { ObjectCodec oc = jp.getCodec(); JsonNode node = oc.readTree(jp); if (node.isObject()) { List<CoinMarketCapTicker> tickers = new LinkedList<>(); ObjectMapper mapper = new ObjectMapper(); SimpleModule module = new SimpleModule(); module.addDeserializer( CoinMarketCapTicker.class, new CoinMarketCapTicker.CoinMarketCapTickerDeserializer()); mapper.registerModule(module); for (JsonNode child : node.get("data")) { tickers.add(mapper.treeToValue(child, CoinMarketCapTicker.class)); } return new CoinMarketCapArrayData<>(tickers); } return null; } }
public <T> T getWith(Class<T> c){ try { return getMapper().treeToValue(objectNode, c); } catch (JsonProcessingException e) { throw new LogicalPlanParsingException(String.format("Failure while trying to convert late bound json type to type of %s.", c.getCanonicalName()), e); } }
@Override public Object fromHash(Map<String, Object> hash) { try { if (flatten) { return typingMapper.reader().forType(Object.class) .readValue(untypedMapper.writeValueAsBytes(doUnflatten(hash))); } return typingMapper.treeToValue(untypedMapper.valueToTree(hash), Object.class); } catch (IOException e) { throw new MappingException(e.getMessage(), e); } }
@Override public T fromJsonNode( final JsonNode node, final ObjectMapper objectMapper ) { try { final Class<? extends T> classType = getType(); return objectMapper.treeToValue( node, classType ); } catch ( JsonProcessingException e ) { throw new CursorParseException( "Unable to deserialize value", e ); } }
@Override public Optional<QueryStats> handle(Request request, Response response) { if (response.getStatusCode() == HttpStatus.GONE.code()) { return Optional.empty(); } else if (response.getStatusCode() != HttpStatus.OK.code()) { throw new RuntimeException("unexpected error code " + response.getStatusCode() + "; reason=" + response.getStatusMessage()); } try { JsonNode rootNode = objectMapper.readTree(response.getInputStream()); JsonNode queryStatsNode = rootNode.get("queryStats"); if (queryStatsNode == null) { return Optional.empty(); } QueryStats queryStats = objectMapper.treeToValue(queryStatsNode, QueryStats.class); return Optional.of(queryStats); } catch (IOException e) { throw new UncheckedIOException(e); } } }
private ObjectNode simpleTypeSchema(JsonNode exampleValue) { try { Object valueAsJavaType = this.objectMapper.treeToValue(exampleValue, Object.class); SchemaAware valueSerializer = getValueSerializer(valueAsJavaType); return (ObjectNode) valueSerializer.getSchema(this.objectMapper.getSerializerProvider(), null); } catch (JsonProcessingException e) { throw new GenerationException("Unable to generate a schema for this json example: " + exampleValue, e); } }
/** * @throws Exception If failed. */ @Test public void testGetAll() throws Exception { final Map<String, String> entries = F.asMap("getKey1", "getVal1", "getKey2", "getVal2"); jcache().putAll(entries); String ret = content(DEFAULT_CACHE_NAME, GridRestCommand.CACHE_GET_ALL, "k1", "getKey1", "k2", "getKey2" ); info("Get all command result: " + ret); JsonNode res = assertResponseSucceeded(ret, true); assertTrue(res.isObject()); assertEquals(entries, JSON_MAPPER.treeToValue(res, Map.class)); }