Refine search
/** * 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 is equivalent to: *<pre> * withType(valueType).readValues(jp); *</pre> */ @Override public <T> Iterator<T> readValues(JsonParser jp, Class<T> valueType) throws IOException, JsonProcessingException { return withType(valueType).readValues(jp); }
/** * Factory method for constructing {@link ObjectReader} that will * use specified injectable values. * * @param injectableValues Injectable values to use * * @since 1.9 */ public ObjectReader reader(InjectableValues injectableValues) { return new ObjectReader(this, copyDeserializationConfig(), null, null, null, injectableValues); }
@Override public <T> T treeToValue(JsonNode n, Class<T> valueType) throws IOException, JsonProcessingException { return readValue(treeAsTokens(n), valueType); }
ObjectMapper objectMapper = new ObjectMapper(); final Timer.Context httpEventsIngestTimerContext = httpEventsIngestTimer.time(); try { request.content().writerIndex(), CharsetUtil.UTF_8); Event event = objectMapper.readValue(body, Event.class); Iterator<Event> iterator = objectMapper.reader(Event.class).readValues(body); if (iterator.hasNext()) { iterator.next();
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(); }
@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 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); }
/** * Method that binds content read from given byte array, * using configuration of this reader. * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") public <T> T readValue(byte[] src) throws IOException, JsonProcessingException { return (T) _bindAndClose(_jsonFactory.createJsonParser(src)); }
/** * Method that reads content from given input source, * using configuration of this reader, and binds it as JSON Tree. *<p> * Note that if an object was specified with a call to * {@link #withValueToUpdate(Object)} * it will just be ignored; result is always a newly constructed * {@link JsonNode} instance. */ public JsonNode readTree(Reader r) throws IOException, JsonProcessingException { return _bindAndCloseAsTree(_jsonFactory.createJsonParser(r)); }
/** * Factory method for constructing {@link ObjectReader} that will * use specified {@link JsonNodeFactory} for constructing JSON trees. * * @since 1.6 */ public ObjectReader reader(JsonNodeFactory f) { return new ObjectReader(this, copyDeserializationConfig()).withNodeFactory(f); }
/** * Factory method for constructing {@link ObjectReader} with * default settings. Note that the resulting instance is NOT usable as is, * without defining expected value type. * * @since 1.6 */ public ObjectReader reader() { return new ObjectReader(this, copyDeserializationConfig()) .withInjectableValues(_injectableValues); }
/** * Since 1.9.3 */ public final <T> MappingIterator<T> readValues(byte[] src) throws IOException, JsonProcessingException { return readValues(src, 0, src.length); }
/** * Convenience method for converting results from given JSON tree into given * value type. Basically short-cut for: *<pre> * objectReader.readValue(src.traverse()) *</pre> */ @SuppressWarnings("unchecked") public <T> T readValue(JsonNode src) throws IOException, JsonProcessingException { return (T) _bindAndClose(treeAsTokens(src)); }
/** * Method for constructing a new reader instance that is configured * to data bind into specified type. *<p> * Note that the method does NOT change state of this reader, but * rather construct and returns a newly configured instance. */ public ObjectReader withType(JavaType valueType) { if (valueType == _valueType) return this; // type is stored here, no need to make a copy of config return new ObjectReader(this, _config, valueType, _valueToUpdate, _schema, _injectableValues); }
/** * Method that binds content read using given parser, using * configuration of this reader, including expected result type. * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") public <T> T readValue(JsonParser jp) throws IOException, JsonProcessingException { return (T) _bind(jp); }
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(); }
/** * Method that binds content read from given input source, * using configuration of this reader. * Value return is either newly constructed, or root value that * was specified with {@link #withValueToUpdate(Object)}. */ @SuppressWarnings("unchecked") public <T> T readValue(InputStream src) throws IOException, JsonProcessingException { return (T) _bindAndClose(_jsonFactory.createJsonParser(src)); }