public static <E> ObjectReader reader(final ObjectMapper mapper, final Class<E> clazz) { return new ObjectReader() { private final org.codehaus.jackson.map.ObjectReader or = mapper.reader(clazz); @Override public <T> Iterator<T> readValues(JsonParser parser) throws IOException { return or.readValues(parser); } }; } }
/** * @deprecated Since 1.9, use {@link #reader(FormatSchema)} instead. */ @Deprecated public ObjectReader schemaBasedReader(FormatSchema schema) { return reader(schema); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(TypeReference<?> type) { return reader(_typeFactory.constructType(type)); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(Class<?> type) { return reader(_typeFactory.constructType(type)); }
/** * @deprecated Since 1.9, use {@link #reader(FormatSchema)} instead. */ @Deprecated public ObjectReader schemaBasedReader(FormatSchema schema) { return reader(schema); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(Class<?> type) { return reader(_typeFactory.constructType(type)); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(TypeReference<?> type) { return reader(_typeFactory.constructType(type)); }
Iterator<Event> iterator = objectMapper.reader(Event.class).readValues(body); if (iterator.hasNext()) { iterator.next();
public static <E> ObjectReader reader(final ObjectMapper mapper, final Class<E> clazz) { return new ObjectReader() { private final org.codehaus.jackson.map.ObjectReader or = mapper.reader(clazz); @Override public <T> Iterator<T> readValues(JsonParser parser) throws IOException { return or.readValues(parser); } }; } }
public static <E> ObjectReader reader(final ObjectMapper mapper, final Class<E> clazz) { return new ObjectReader() { private final org.codehaus.jackson.map.ObjectReader or = mapper.reader(clazz); @Override public <T> Iterator<T> readValues(JsonParser parser) throws IOException { return or.readValues(parser); } }; } }
/** * @deprecated Since 1.9, use {@link #reader(FormatSchema)} instead. */ @Deprecated public ObjectReader schemaBasedReader(FormatSchema schema) { return reader(schema); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(Class<?> type) { return reader(_typeFactory.constructType(type)); }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(TypeReference<?> type) { return reader(_typeFactory.constructType(type)); }
/** * 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); } }
/** * Factory method for constructing {@link ObjectReader} that will * read or update instances of specified type * * @since 1.6 */ public ObjectReader reader(TypeReference<?> type) { return reader(_typeFactory.constructType(type)); }
<T> T jsonToObject ( String jsonContent, Class<T> type ) { try { return new ObjectMapper().reader( type ).readValue( jsonContent ); } catch ( Exception e ) { throw new RuntimeException( String.format( "Failed to convert JSON '%s' to object", jsonContent ), e ); } }
protected LogFilter jsonToLogFilter(String json) throws IOException { if (json == null) { return null; } json = json.trim(); if (json.length() == 0 || json.equals("{}")) { return null; } return mapper.reader(LogFilter.class).readValue(json); }
@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); }