com.fasterxml.jackson.databind.ObjectMapper._serializerProvider()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中com.fasterxml.jackson.databind.ObjectMapper._serializerProvider()方法的一些代码示例,展示了ObjectMapper._serializerProvider()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectMapper._serializerProvider()方法的具体详情如下:
包路径:com.fasterxml.jackson.databind.ObjectMapper
类名称:ObjectMapper
方法名:_serializerProvider

ObjectMapper._serializerProvider介绍

[英]Object that manages access to serializers used for serialization, including caching. It is configured with #_serializerFactory to allow for constructing custom serializers.

Note: while serializers are only exposed SerializerProvider, mappers and readers need to access additional API defined by DefaultSerializerProvider
[中]

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Accessor for constructing and returning a {@link SerializerProvider}
 * instance that may be used for accessing serializers. This is same as
 * calling {@link #getSerializerProvider}, and calling <code>createInstance</code>
 * on it.
 *
 * @since 2.7
 */
public SerializerProvider getSerializerProviderInstance() {
  return _serializerProvider(_serializationConfig);
}

代码示例来源:origin: redisson/redisson

/**
 * Generate <a href="http://json-schema.org/">Json-schema</a>
 * instance for specified class.
 *
 * @param t The class to generate schema for
 * @return Constructed JSON schema.
 * 
 * @deprecated Since 2.6 use external JSON Schema generator (https://github.com/FasterXML/jackson-module-jsonSchema)
 *    (which under the hood calls {@link #acceptJsonFormatVisitor(JavaType, JsonFormatVisitorWrapper)})
 */
@Deprecated
public com.fasterxml.jackson.databind.jsonschema.JsonSchema generateJsonSchema(Class<?> t)
    throws JsonMappingException {
  return _serializerProvider(getSerializationConfig()).generateJsonSchema(t);
}

代码示例来源:origin: redisson/redisson

/**
 * Method similar to {@link #canSerialize(Class)} but that can return
 * actual {@link Throwable} that was thrown when trying to construct
 * serializer: this may be useful in figuring out what the actual problem is.
 * 
 * @since 2.3
 */
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
  return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, cause);
}

代码示例来源:origin: redisson/redisson

/**
 * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code>
 * method is to be called right after serialization has been called
 */
private final void _configAndWriteCloseable(JsonGenerator g, Object value, SerializationConfig cfg)
  throws IOException
{
  Closeable toClose = (Closeable) value;
  try {
    _serializerProvider(cfg).serializeValue(g, value);
    Closeable tmpToClose = toClose;
    toClose = null;
    tmpToClose.close();
  } catch (Exception e) {
    ClassUtil.closeOnFailAndThrowAsIOE(g, toClose, e);
    return;
  }
  g.close();
}

代码示例来源:origin: redisson/redisson

/**
 * Method for visiting type hierarchy for given type, using specified visitor.
 * Visitation uses <code>Serializer</code> hierarchy and related properties
 *<p>
 * This method can be used for things like
 * generating <a href="http://json-schema.org/">JSON Schema</a>
 * instance for specified type.
 *
 * @param type Type to generate schema for (possibly with generic signature)
 * 
 * @since 2.1
 */
public void acceptJsonFormatVisitor(JavaType type, JsonFormatVisitorWrapper visitor)
  throws JsonMappingException
{
  if (type == null) {
    throw new IllegalArgumentException("type must be provided");
  }
  _serializerProvider(getSerializationConfig()).acceptJsonFormatVisitor(type, visitor);
}

代码示例来源:origin: redisson/redisson

@Override
public void writeTree(JsonGenerator jgen, TreeNode rootNode)
  throws IOException, JsonProcessingException
{
  SerializationConfig config = getSerializationConfig();
  _serializerProvider(config).serializeValue(jgen, rootNode);
  if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
    jgen.flush();
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Method to serialize given JSON Tree, using generator
 * provided.
 */
public void writeTree(JsonGenerator jgen, JsonNode rootNode)
  throws IOException, JsonProcessingException
{
  SerializationConfig config = getSerializationConfig();
  _serializerProvider(config).serializeValue(jgen, rootNode);
  if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
    jgen.flush();
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Method that can be called to check whether mapper thinks
 * it could serialize an instance of given Class.
 * Check is done
 * by checking whether a serializer can be found for the type.
 *<p>
 * NOTE: since this method does NOT throw exceptions, but internal
 * processing may, caller usually has little information as to why
 * serialization would fail. If you want access to internal {@link Exception},
 * call {@link #canSerialize(Class, AtomicReference)} instead.
 *
 * @return True if mapper can find a serializer for instances of
 *  given class (potentially serializable), false otherwise (not
 *  serializable)
 */
public boolean canSerialize(Class<?> type) {
  return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, null);
}

代码示例来源:origin: redisson/redisson

/**
 * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code>
 * method is to be called right after serialization has been called
 */
private final void _writeCloseableValue(JsonGenerator g, Object value, SerializationConfig cfg)
  throws IOException
{
  Closeable toClose = (Closeable) value;
  try {
    _serializerProvider(cfg).serializeValue(g, value);
    if (cfg.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
      g.flush();
    }
  } catch (Exception e) {
    ClassUtil.closeOnFailAndThrowAsIOE(null, toClose, e);
    return;
  }
  toClose.close();
}

代码示例来源:origin: redisson/redisson

/**
 * Method called to configure the generator as necessary and then
 * call write functionality
 */
protected final void _configAndWriteValue(JsonGenerator g, Object value)
  throws IOException
{
  SerializationConfig cfg = getSerializationConfig();
  cfg.initialize(g); // since 2.5
  if (cfg.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
    _configAndWriteCloseable(g, value, cfg);
    return;
  }
  try {
    _serializerProvider(cfg).serializeValue(g, value);
  } catch (Exception e) {
    ClassUtil.closeOnFailAndThrowAsIOE(g, e);
    return;
  }
  g.close();
}

代码示例来源:origin: redisson/redisson

/**
 * Method that can be used to serialize any Java value as
 * JSON output, using provided {@link JsonGenerator}.
 */
@Override
public void writeValue(JsonGenerator g, Object value)
  throws IOException, JsonGenerationException, JsonMappingException
{
  SerializationConfig config = getSerializationConfig();
  /* 12-May-2015/2.6, tatu: Looks like we do NOT want to call the usual
   *    'config.initialize(g)` here, since it is assumed that generator
   *    has been configured by caller. But for some reason we don't
   *    trust indentation settings...
   */
  // 10-Aug-2012, tatu: as per [Issue#12], must handle indentation:
  if (config.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
    if (g.getPrettyPrinter() == null) {
      g.setPrettyPrinter(config.constructDefaultPrettyPrinter());
    }
  }
  if (config.isEnabled(SerializationFeature.CLOSE_CLOSEABLE) && (value instanceof Closeable)) {
    _writeCloseableValue(g, value, config);
  } else {
    _serializerProvider(config).serializeValue(g, value);
    if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
      g.flush();
    }
  }
}

代码示例来源:origin: redisson/redisson

_serializerProvider(config).serializeValue(buf, fromValue);

代码示例来源:origin: redisson/redisson

SerializationConfig config = getSerializationConfig().
    without(SerializationFeature.WRAP_ROOT_VALUE);
_serializerProvider(config).serializeValue(buf, overrides);
JsonParser p = buf.asParser();
result = readerForUpdating(valueToUpdate).readValue(p);

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Generate <a href="http://json-schema.org/">Json-schema</a>
 * instance for specified class.
 *
 * @param t The class to generate schema for
 * @return Constructed JSON schema.
 */
@SuppressWarnings("deprecation")
public com.fasterxml.jackson.databind.jsonschema.JsonSchema generateJsonSchema(Class<?> t)
    throws JsonMappingException {
  return _serializerProvider(getSerializationConfig()).generateJsonSchema(t);
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

/**
 * Method similar to {@link #canSerialize(Class)} but that can return
 * actual {@link Throwable} that was thrown when trying to construct
 * serializer: this may be useful in figuring out what the actual problem is.
 *
 * @since 2.3
 */
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
  return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, cause);
}

代码示例来源:origin: com.fasterxml.jackson.core/com.springsource.com.fasterxml.jackson.core.jackson-databind

/**
 * Generate <a href="http://json-schema.org/">Json-schema</a>
 * instance for specified class.
 *
 * @param t The class to generate schema for
 * @return Constructed JSON schema.
 */
public JsonSchema generateJsonSchema(Class<?> t) throws JsonMappingException {
  return _serializerProvider(getSerializationConfig()).generateJsonSchema(t);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * Generate <a href="http://json-schema.org/">Json-schema</a>
 * instance for specified class.
 *
 * @param t The class to generate schema for
 * @return Constructed JSON schema.
 */
public JsonSchema generateJsonSchema(Class<?> t) throws JsonMappingException {
  return _serializerProvider(getSerializationConfig()).generateJsonSchema(t);
}

代码示例来源:origin: hstaudacher/osgi-jax-rs-connector

/**
 * Method similar to {@link #canSerialize(Class)} but that can return
 * actual {@link Throwable} that was thrown when trying to construct
 * serializer: this may be useful in figuring out what the actual problem is.
 * 
 * @since 2.3
 */
public boolean canSerialize(Class<?> type, AtomicReference<Throwable> cause) {
  return _serializerProvider(getSerializationConfig()).hasSerializerFor(type, cause);
}

代码示例来源:origin: com.jwebmp.jackson.core/jackson-databind

@Override
public void writeTree(JsonGenerator jgen, TreeNode rootNode)
  throws IOException, JsonProcessingException
{
  SerializationConfig config = getSerializationConfig();
  _serializerProvider(config).serializeValue(jgen, rootNode);
  if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
    jgen.flush();
  }
}

代码示例来源:origin: Nextdoor/bender

@Override
public void writeTree(JsonGenerator jgen, TreeNode rootNode)
  throws IOException, JsonProcessingException
{
  SerializationConfig config = getSerializationConfig();
  _serializerProvider(config).serializeValue(jgen, rootNode);
  if (config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
    jgen.flush();
  }
}

相关文章

微信公众号

最新文章

更多

ObjectMapper类方法