本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectReader类的典型用法代码示例。如果您正苦于以下问题:Java ObjectReader类的具体用法?Java ObjectReader怎么用?Java ObjectReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectReader类属于com.fasterxml.jackson.databind包,在下文中一共展示了ObjectReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkCaptcha
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
public boolean checkCaptcha(String captcha) {
if (isBlank(captcha)) {
throw new ErrorCheckCaptcha("error.captcha.required", "Captcha is blank");
}
String url = getReCaptcha().getUrl() + "?secret=" + getReCaptcha().getSecretKey() + "&response=" + captcha;
log.debug("Check captcha by url {}", url);
final ObjectReader reader = new ObjectMapper().readerFor(Map.class);
try {
final MappingIterator<Map<String, Object>> result = reader.readValues(new URL(url));
Map<String, Object> resultMap = result.nextValue();
log.info("Captacha result map {}", resultMap);
Boolean success = (Boolean) resultMap.get("success");
return success;
} catch (IOException e) {
throw new ErrorCheckCaptcha(e);
}
}
示例2: decode
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
public Map<String, Object> decode(String base64EncodedKey, String content) {
try {
byte[] decodedKey = Base64.getDecoder().decode(base64EncodedKey);
SecretKey key = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES");
JWEObject jwe = JWEObject.parse(content);
jwe.decrypt(new AESDecrypter(key));
ObjectMapper objectMapper = new ObjectMapper();
ObjectReader reader = objectMapper.readerFor(Map.class);
return reader.with(DeserializationFeature.USE_LONG_FOR_INTS)
.readValue(jwe.getPayload().toString());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: findAll
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
@Override
public List<KeyValueConfigEntity> findAll(@Nonnull KeyValueConfigName configName) throws Exception {
Objects.requireNonNull(configName);
String collectionName = configName.getQualifiedName();
MongoCollection<RawBsonDocument> collection =
connector.getDatabase().getCollection(collectionName, RawBsonDocument.class);
MongoCursor<RawBsonDocument> it = collection.find().iterator();
if (!it.hasNext()) {
return Collections.emptyList();
}
RawBsonDocument document = it.next();
ByteArrayInputStream bin = new ByteArrayInputStream(document.getByteBuffer().array());
ObjectMapper objectMapper = MongoConfigObjectMapper.getInstance();
ObjectReader objectReader = objectMapper.readerFor(MongoConfigEntity.class);
List<KeyValueConfigEntity> result = ((MongoConfigEntity) objectReader.readValue(bin)).getConfig();
// set groupName on returned config key-value pairs
return result.stream().map(input -> input.setConfigName(configName)).collect(Collectors.toList());
}
示例4: 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);
}
}
}
示例5: 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();
}
}
示例6: ParallelRecordReader
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
public ParallelRecordReader(CommittableFileLog cfl, int numLinesPerBatch, ObjectReader vReader, ObjectReader eReader) {
super(cfl, vReader, eReader);
this.numLinesPerBatch = numLinesPerBatch;
this.numProcessors = Runtime.getRuntime().availableProcessors() - 1; // one to insert, read is not 100% busy
if (numProcessors < 1) {
this.numProcessors = 1;
} else if (numProcessors > 4) {
this.numProcessors = 4; // Don't need more than 4 threads
}
this.numBatchInQueue = QUEUE_TO_PROCESSOR_RATIO * numProcessors;
this.producerService = Executors.newSingleThreadExecutor();
this.deserializerService = Executors.newFixedThreadPool(numProcessors);
this.queue = new ArrayBlockingQueue<Batch>(numBatchInQueue);
// This keeps filling up the queue
producerService.submit(new ProducerTask());
}
示例7: 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());
}
}
示例8: 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 );
}
}
示例9: 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);
}
}
}
示例10: 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;
}
示例11: getFromList
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
/**
* Get values from a list.
*
* @param key The list key
* @param reader The object reader
* @param offset From where
* @param count The number of items to retrieve
* @param <T> Generic type of something implementing {@code java.io.Serializable}
* @return The values list
* @since 17.08.20
*/
private <T> List<T> getFromList(final String key, final ObjectReader reader, final int offset, final int count) {
final List<T> objects = new ArrayList<>();
try {
final List<String> rawData;
try (final Jedis jedis = this.getConnection()) {
rawData = jedis.lrange(key, offset, count > 0 ? count - 1 : count);
}
if (rawData != null) {
for (final String s : rawData) {
objects.add(reader.readValue(s));
}
}
} catch (IOException | NullPointerException ex) {
PlayRedisImpl.LOG.error("Can't get object from list", ex);
}
return objects;
}
示例12: 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);
}
示例13: ParserGroundTruth
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
public ParserGroundTruth(final InputStream is) throws IOException {
try(final BufferedReader reader =
new BufferedReader(
new InputStreamReader(is, "UTF-8"))) {
ObjectMapper om = new ObjectMapper();
ObjectReader r = om.reader().forType(new TypeReference<Paper>() {});
papers = new ArrayList<Paper>();
while (true) {
final String line = reader.readLine();
if (line == null)
break;
papers.add(r.readValue(line));
}
}
log.info("Read " + papers.size() + " papers.");
buildLookup();
papers.forEach((Paper p) -> {
for (int i = 0; i < p.authors.length; i++)
p.authors[i] = invertAroundComma(p.authors[i]);
});
}
示例14: apply
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
Context apply(String s, Map<String, String> args, boolean isBatch, Handle dbiHandle, Map<String, String> parameters, NameList names) throws IOException {
ObjectReader mapper = new ObjectMapper().readerFor(Object.class);
HashMap<String, Object> parsedArgs = new HashMap<>();
for (Map.Entry<String, String> a : args.entrySet()) {
try {
parsedArgs.put(a.getKey(), mapper.readValue(a.getValue()));
} catch (Exception e) {
parsedArgs.put(a.getKey(), a.getValue());
}
}
Handlebars handlebars = new Handlebars().with(EscapingStrategy.NOOP);
this.parameters = parameters;
StringHelper.register(handlebars);
StringHelpers.register(handlebars);
FilterHelper.register(handlebars);
ConditionalHelper.register(handlebars);
new ParameterHelper(parameters, names).registerHelper(handlebars);
eh = new EachHelper(parameters, names, isBatch, dbiHandle).registerHelper(handlebars);
template = handlebars.compileInline(s);
sql = template.apply(parsedArgs);
return this;
}
示例15: downloadResult
import com.fasterxml.jackson.databind.ObjectReader; //导入依赖的package包/类
private List<ArrayNode> downloadResult(String jobId)
{
return client.jobResult(jobId, TDResultFormat.JSON, input -> {
try {
List<String> lines = CharStreams.readLines(new InputStreamReader(input));
ObjectReader reader = objectMapper().readerFor(ArrayNode.class);
List<ArrayNode> result = new ArrayList<>();
for (String line : lines) {
result.add(reader.readValue(line));
}
return result;
}
catch (IOException e) {
throw Throwables.propagate(e);
}
});
}