当前位置: 首页>>代码示例>>Java>>正文


Java ObjectReader.readValue方法代码示例

本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectReader.readValue方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectReader.readValue方法的具体用法?Java ObjectReader.readValue怎么用?Java ObjectReader.readValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.fasterxml.jackson.databind.ObjectReader的用法示例。


在下文中一共展示了ObjectReader.readValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setMeta

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
protected void setMeta(Resource dataBody, Object instance, ResourceInformation resourceInformation) {
	ResourceField metaField = resourceInformation.getMetaField();
	if (dataBody.getMeta() != null && metaField != null) {
		JsonNode metaNode = dataBody.getMeta();

		Class<?> metaClass = metaField.getType();

		ObjectReader metaMapper = objectMapper.readerFor(metaClass);
		try {
			Object meta = metaMapper.readValue(metaNode);
			metaField.getAccessor().setValue(instance, meta);
		} catch (IOException e) {
			throw new ResponseBodyException("failed to parse links information", e);
		}

	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:18,代码来源:ClientResourceUpsert.java

示例2: close

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    try {
        final EncryptedDataContainer encrypted = cipher.doFinal();
        super.write(encrypted.getContent());
        final String tag = CryptoUtils.byteArrayToString(encrypted.getTag());
        final ObjectReader reader = session.getClient().getJSON().getContext(null).readerFor(FileKey.class);
        final FileKey fileKey = reader.readValue(status.getFilekey().array());
        fileKey.setTag(tag);
        final ObjectWriter writer = session.getClient().getJSON().getContext(null).writerFor(FileKey.class);
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        writer.writeValue(out, fileKey);
        status.setFilekey(ByteBuffer.wrap(out.toByteArray()));
    }
    catch(CryptoSystemException e) {
        throw new IOException(e);
    }
    finally {
        super.close();
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:22,代码来源:CryptoOutputStream.java

示例3: constructList

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Constructs the object based on the content as a List, the JSON can be an array or just a single value without the [] symbols
 * @param content Reader
 * @return A collection of the specified type
 */
public <T> List<T> constructList(Reader content, Class<T> requiredType)
{
    ObjectReader reader = objectMapper.readerFor(TypeFactory.defaultInstance().constructParametricType(List.class, requiredType));
    try
    {
        List<T> toReturn = reader.readValue(content);
        if (toReturn == null || toReturn.isEmpty())
        {
          throw new InvalidArgumentException("Could not read content from HTTP request body, the list is empty");
        }
        return toReturn;
    }
    catch (IOException error)
    {
        throw new InvalidArgumentException("Could not read content from HTTP request body: "+error.getMessage());
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:23,代码来源:JacksonHelper.java

示例4: reload

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Reload.
 *
 * @throws HmsException the hms exception
 */
public void reload()
    throws HmsException
{
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectReader objectReader = objectMapper.readerForUpdating( this );
    try
    {
        objectReader.readValue( new File( filename ) );
    }
    catch ( IOException e )
    {
        logger.error( "Error reloading HMS inventory configuration file: {}.", filename, e );
        throw new HmsException( "Error reloading HMS inventory configuration file: " + filename, e );
    }
}
 
开发者ID:vmware,项目名称:OHMS,代码行数:21,代码来源:HmsInventoryConfiguration.java

示例5: setMeta

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
protected void setMeta(Resource dataBody, Object instance, ResourceInformation resourceInformation) {
	ResourceField metaField = resourceInformation.getMetaField();
	if (dataBody.getMeta() != null && metaField != null) {
		JsonNode metaNode = dataBody.getMeta();

		Class<?> metaClass = metaField.getType();

		ObjectReader metaMapper = objectMapper.readerFor(metaClass);
		try {
			Object meta = metaMapper.readValue(metaNode);
			PropertyUtils.setProperty(instance, metaField.getUnderlyingName(), meta);
		} catch (IOException e) {
			throw new ResponseBodyException("failed to parse links information", e);
		}

	}
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:18,代码来源:ClientResourceUpsert.java

示例6: get

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Retrieves an object by key.
 *
 * @param key    Item key
 * @param reader The object reader
 * @param <T>    Generic type of something
 * @return The object or null.
 * @since 17.08.20
 */
private <T> T get(final String key, final ObjectReader reader) {
    T object = null;
    try {
        final String rawData;
        try (final Jedis jedis = this.getConnection()) {
            rawData = jedis.get(key);
        }
        if (rawData != null) {
            object = reader.readValue(rawData.getBytes());
        }
    } catch (final IOException ex) {
        PlayRedisImpl.LOG.error("Can't get object", ex);
    }
    return object;
}
 
开发者ID:0xbaadf00d,项目名称:play-redis-module,代码行数:25,代码来源:PlayRedisImpl.java

示例7: unmarshall

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
@Override
public <T> T unmarshall(final Object marshalled, final Class<T> type) throws Exception {
  checkNotNull(marshalled);
  checkState(marshalled instanceof Map, "Marshalled data must be a Map; found: %s", marshalled.getClass());

  // FIXME: This allows the top-level object to be created, but if any children objects of this are missing
  // FIXME: ... no-arg CTOR then Jackson will fail to construct them.
  // FIXME: Is there any way to configure the basic instance creation for Jackson?
  Object value = instanceCreator.newInstance(type);

  // performs same basic logic as ObjectMapper.convertValue(Object, Class) helper
  ObjectReader reader = objectMapper.readerForUpdating(value);
  TokenBuffer buff = new TokenBuffer(objectMapper, false);
  objectMapper.writeValue(buff, marshalled);
  reader.readValue(buff.asParser());

  return type.cast(value);
}
 
开发者ID:sonatype,项目名称:nexus-public,代码行数:19,代码来源:JacksonMarshaller.java

示例8: convertRequest

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Converts the specified {@link AggregatedHttpMessage} to an object of {@code expectedResultType}.
 */
@Override
public Object convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage request,
                             Class<?> expectedResultType) throws Exception {

    final MediaType contentType = request.headers().contentType();
    if (contentType != null && (contentType.is(MediaType.JSON) ||
                                contentType.subtype().endsWith("+json"))) {
        final ObjectReader reader = readers.computeIfAbsent(expectedResultType, mapper::readerFor);
        if (reader != null) {
            final String content = request.content().toString(
                    contentType.charset().orElse(StandardCharsets.UTF_8));
            try {
                return reader.readValue(content);
            } catch (JsonProcessingException e) {
                throw new IllegalArgumentException("failed to parse a JSON document: " + e, e);
            }
        }
    }
    return RequestConverterFunction.fallthrough();
}
 
开发者ID:line,项目名称:armeria,代码行数:24,代码来源:JacksonRequestConverterFunction.java

示例9: loadMoviesFromDatabase

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Load movies from database.
 */
void loadMoviesFromDatabase(MVMap<UUID, String> movieMap, ObjectMapper objectMapper) {
  // load movies
  ObjectReader movieObjectReader = objectMapper.readerFor(Movie.class);

  for (UUID uuid : new ArrayList<>(movieMap.keyList())) {
    String json = "";
    try {
      json = movieMap.get(uuid);
      Movie movie = movieObjectReader.readValue(json);
      movie.setDbId(uuid);
      // for performance reasons we add movies directly
      movieList.add(movie);
    }
    catch (Exception e) {
      LOGGER.warn("problem decoding movie json string: " + e.getMessage());
      LOGGER.info("dropping corrupt movie");
      movieMap.remove(uuid);
    }
  }
  LOGGER.info("found " + movieList.size() + " movies in database");
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:25,代码来源:MovieList.java

示例10: loadMovieSetsFromDatabase

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
void loadMovieSetsFromDatabase(MVMap<UUID, String> movieSetMap, ObjectMapper objectMapper) {
  // load movie sets
  ObjectReader movieSetObjectReader = objectMapper.readerFor(MovieSet.class);

  for (UUID uuid : new ArrayList<>(movieSetMap.keyList())) {
    try {
      MovieSet movieSet = movieSetObjectReader.readValue(movieSetMap.get(uuid));
      movieSet.setDbId(uuid);
      // for performance reasons we add movies sets directly
      movieSetList.add(movieSet);
    }
    catch (Exception e) {
      LOGGER.warn("problem decoding movie set json string: " + e.getMessage());
      LOGGER.info("dropping corrupt movie set");
      movieSetMap.remove(uuid);
    }
  }

  LOGGER.info("found " + movieSetList.size() + " movieSets in database");
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:21,代码来源:MovieList.java

示例11: loadTvShowsFromDatabase

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Load tv shows from database.
 */
void loadTvShowsFromDatabase(MVMap<UUID, String> tvShowMap, ObjectMapper objectMapper) {
  // load all TV shows from the database
  ObjectReader tvShowObjectReader = objectMapper.readerFor(TvShow.class);

  for (UUID uuid : new ArrayList<>(tvShowMap.keyList())) {
    try {
      TvShow tvShow = tvShowObjectReader.readValue(tvShowMap.get(uuid));
      tvShow.setDbId(uuid);

      // for performance reasons we add tv shows directly
      tvShowList.add(tvShow);
    }
    catch (Exception e) {
      LOGGER.warn("problem decoding TV show json string: " + e.getMessage());
      LOGGER.info("dropping corrupt TV show");
      tvShowMap.remove(uuid);
    }
  }
  LOGGER.info("found " + tvShowList.size() + " TV shows in database");
}
 
开发者ID:tinyMediaManager,项目名称:tinyMediaManager,代码行数:24,代码来源:TvShowList.java

示例12: testJsonDeserialization

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
@Test
public void testJsonDeserialization() throws Exception {
    InputStream is = null;
    try {
        is = getClass().getResourceAsStream(
                "/decisions/examples/Ch11LoanExample.json");
        ObjectMapper mapper = new ObjectMapper();
        // we'll be reading instances of MyBean
        ObjectReader reader = mapper.readerFor(DmnModel.class);
        // and then do other configuration, if any, and read:
        DmnModel result = reader.readValue(is);
        assertNotNull(result);
    } catch (Exception e) {
        e.printStackTrace();
        // fail("unable to find test resource");
    }
    // DmnModel dmnModel = de.getRepositoryService().createModelForTenant(
    // ch11LoanExample.getDmnModel());
    // transformAndAssert(dmnModel, "applicationRiskScoreModel_bkm");
}
 
开发者ID:OneDecision,项目名称:one-decision,代码行数:21,代码来源:Ch11LoanExampleTest.java

示例13: parseResponse

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
/**
 * Parse response into data model object.
 * 
 * @param unwrap Unwrap datamodel
 * @return Response datamodel
 * @throws IOException
 */
public T parseResponse() throws IOException {
	ObjectReader reader = MAPPER.readerFor(datamodel).without(Feature.AUTO_CLOSE_SOURCE);
	if (datamodel.isAnnotationPresent(JsonRootName.class)) {
		reader = reader.with(DeserializationFeature.UNWRAP_ROOT_VALUE);
	}

	try (final InputStream is = response.getStream()) {
		final T result = reader.readValue(is);

		/*
		 * ObjectReader.readValue might not consume the entire inputstream,
		 * we skip everything after the json root element.
		 * This is needed for proper http connection reuse (keep alive).
		 */
		is.skip(Long.MAX_VALUE);

		return result;
	}
}
 
开发者ID:rockihack,项目名称:Stud.IP-FileSync,代码行数:27,代码来源:JacksonRequest.java

示例14: load

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
public static <T extends Config> T load(TypeReference<?> configClazz, InputStream configInput, String configPath, InputStream defaultConfigInput) throws IOException, ConfigValidationException {
    Objects.requireNonNull(configClazz);
    Objects.requireNonNull(configInput);
    final ObjectMapper mapper = createObjectMapper();
    T defaultConfig;
    ObjectReader updater = null;
    if (defaultConfigInput != null) {
        defaultConfig = mapper.readValue(defaultConfigInput, configClazz);
        updater = mapper.readerForUpdating(defaultConfig);
    }
    T config;
    if (updater != null) {
        config = updater.readValue(configInput);
    } else {
        config = mapper.readValue(configInput, configClazz);
    }
    config.configFolder = Resource.from(configPath).getParent();
    //validate(config);
    return config;
}
 
开发者ID:rojanu,项目名称:thrift-swift-finagle-example,代码行数:21,代码来源:Config.java

示例15: applySomePropertiesToAnObject

import com.fasterxml.jackson.databind.ObjectReader; //导入方法依赖的package包/类
@Test
public void applySomePropertiesToAnObject() throws JsonProcessingException, IOException {
	ExtensionApplication extensionApplication = new ExtensionApplication();
	extensionApplication.setAffiliateDetails(new AffiliateDetails());
	extensionApplication.setNotesInternal("internalNotes");
	
	String incomingJSON = "{ \"notesInternal\": \"new value\"}";
	
	ObjectMapper objectMapper = new ObjectMapper();
	ObjectReader readerForUpdating = objectMapper.readerForUpdating(extensionApplication);
	
	JsonNode tree = objectMapper.readTree(incomingJSON);
	readerForUpdating.readValue(tree);
	
	Assert.assertEquals("new value", extensionApplication.getNotesInternal());
}
 
开发者ID:IHTSDO,项目名称:MLDS,代码行数:17,代码来源:PartialCopyTest.java


注:本文中的com.fasterxml.jackson.databind.ObjectReader.readValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。