@Override public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonProcessingException { return readValue(treeAsTokens(n), valueType); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException { return (T) withType(valueType).readValue(jp); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return (T) withType(valueTypeRef).readValue(jp); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException { return (T) withType(valueType).readValue(jp); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException { return (T) withType(valueType).readValue(jp); }
@Override public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonProcessingException { return readValue(treeAsTokens(n), valueType); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException { return (T) withType(valueType).readValue(jp); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return (T) withType(valueTypeRef).readValue(jp); }
private Map<String, Object> _jsonToMap(String jsonString) { try { return objectReader.readValue(jsonString); } catch (IOException e) { throw new RuntimeException("Unable to parse JSON", e); } }
@Override public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonProcessingException { return readValue(treeAsTokens(n), valueType); }
/** * Convenience method that binds content read using given parser, using * configuration of this reader, except that expected value type * is specified with the call (instead of currently configured root type). * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, JavaType valueType) throws IOException, JsonProcessingException { return (T) withType(valueType).readValue(jp); }
/** * Read the auth token from the JSON string. * @param json */ public static final AuthToken fromJSON(String json) { try { return mapper.reader(AuthToken.class).readValue(json); } catch (Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") @Override public <T> T readValue(JsonParser jp, TypeReference<?> valueTypeRef) throws IOException, JsonProcessingException { return (T) withType(valueTypeRef).readValue(jp); }
<T> T jsonToObject ( File jsonFile, Class<T> type ) { try { return new ObjectMapper().reader( type ).readValue( jsonFile ); } catch ( Exception e ) { throw new RuntimeException( String.format( "Failed to convert JSON file '%s' to object", jsonFile ), e ); } }
@Override public <T> T deSer(String src, Class<T> type) throws Exception { ObjectReader reader = mapper.reader(type); return (T) reader.readValue(src); }
@Override public T fromString(String string) { try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); ObjectReader reader = mapper.reader(clazz); return reader.readValue(string); } catch (IOException e) { throw Throwables.propagate(e); } }
public static void fromMap(Object object, Map map) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); SimpleDateFormat sdf = new SimpleDateFormat(OpsGenieClientConstants.Common.API_DATE_FORMAT); mapper.setDateFormat(sdf); mapper.readerForUpdating(object).readValue(mapper.writeValueAsString(map)); if (object instanceof ConvertFromTimeZone) ((ConvertFromTimeZone) object).setTime(); }
public static void fromJson(Object object, JsonParser parser) throws IOException, ParseException { ObjectMapper mapper = new ObjectMapper(); SimpleDateFormat sdf = new SimpleDateFormat(OpsGenieClientConstants.Common.API_DATE_FORMAT); mapper.setDateFormat(sdf); mapper.readerForUpdating(object).readValue(parser); if (object instanceof ConvertFromTimeZone) ((ConvertFromTimeZone) object).setTime(); }
public void load() throws IOException { ObjectMapper mapper = new ObjectMapper(); File file = getSaveFile(); this.state = mapper.reader(BlockIteratorState.class).readValue(file); LOG.trace("load({}, {}): loaded iterator {} from {}: {}", storageID, bpid, name, file.getAbsoluteFile(), mapper.writerWithDefaultPrettyPrinter().writeValueAsString(state)); }
@Test public void testGetXAttrFromJson() throws IOException { String jsonString = "{\"XAttrs\":[{\"name\":\"user.a1\",\"value\":\"0x313233\"}," + "{\"name\":\"user.a2\",\"value\":\"0x313131\"}]}"; ObjectReader reader = new ObjectMapper().reader(Map.class); Map<?, ?> json = reader.readValue(jsonString); // Get xattr: user.a2 byte[] value = JsonUtil.getXAttr(json, "user.a2"); Assert.assertArrayEquals(XAttrCodec.decodeValue("0x313131"), value); }