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

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

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

ObjectMapper.getFactory介绍

[英]Method that can be used to get hold of JsonFactory that this mapper uses if it needs to construct JsonParsers and/or JsonGenerators.

WARNING: note that all ObjectReader and ObjectWriterinstances created by this mapper usually share the same configured JsonFactory, so changes to its configuration will "leak". To avoid such observed changes you should always use "with()" and "without()" method of ObjectReader and ObjectWriterfor changing com.fasterxml.jackson.core.JsonParser.Featureand com.fasterxml.jackson.core.JsonGenerator.Featuresettings to use on per-call basis.
[中]方法,该方法可用于获取此映射器在需要构造JSONParser和/或JSONGenerator时使用的JsonFactory。
警告:请注意,此映射程序创建的所有ObjectReader和ObjectWriterInstance通常共享相同的已配置JsonFactory,因此对其配置的更改将“泄漏”。为了避免观察到这样的更改,您应该始终使用ObjectReader和ObjectWriter的“with()”和“without()”方法来更改com。fasterxml。杰克逊。果心JsonParser。功能和com。fasterxml。杰克逊。果心JsonGenerator。每次通话使用的功能设置。

代码示例

代码示例来源:origin: apache/incubator-druid

public ArrayWriter(final OutputStream outputStream, final ObjectMapper jsonMapper) throws IOException
{
 this.jsonGenerator = jsonMapper.getFactory().createGenerator(outputStream);
 this.outputStream = outputStream;
}

代码示例来源:origin: apache/incubator-druid

public ObjectWriter(final OutputStream outputStream, final ObjectMapper jsonMapper) throws IOException
{
 this.jsonGenerator = jsonMapper.getFactory().createGenerator(outputStream);
 this.outputStream = outputStream;
}

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

/**
 * @deprecated Since 2.1: Use {@link #getFactory} instead
 */
@Deprecated
@Override
public JsonFactory getJsonFactory() { return getFactory(); }

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * The {@code ObjectMapper} must be configured with a {@code CBORFactory} instance.
 */
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
  Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
  super.setObjectMapper(objectMapper);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Construct a new {@code MappingJackson2CborHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be configured with a {@code CBORFactory} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#cbor()
 */
public MappingJackson2CborHttpMessageConverter(ObjectMapper objectMapper) {
  super(objectMapper, new MediaType("application", "cbor"));
  Assert.isInstanceOf(CBORFactory.class, objectMapper.getFactory(), "CBORFactory required");
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * {@inheritDoc}
 * The {@code ObjectMapper} must be configured with a {@code SmileFactory} instance.
 */
@Override
public void setObjectMapper(ObjectMapper objectMapper) {
  Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
  super.setObjectMapper(objectMapper);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Construct a new {@code MappingJackson2SmileHttpMessageConverter} with a custom {@link ObjectMapper}
 * (must be configured with a {@code SmileFactory} instance).
 * You can use {@link Jackson2ObjectMapperBuilder} to build it easily.
 * @see Jackson2ObjectMapperBuilder#smile()
 */
public MappingJackson2SmileHttpMessageConverter(ObjectMapper objectMapper) {
  super(objectMapper, new MediaType("application", "x-jackson-smile"));
  Assert.isInstanceOf(SmileFactory.class, objectMapper.getFactory(), "SmileFactory required");
}

代码示例来源:origin: spring-projects/spring-framework

public Jackson2SmileDecoder(ObjectMapper mapper, MimeType... mimeTypes) {
  super(mapper, mimeTypes);
  Assert.isAssignable(SmileFactory.class, mapper.getFactory().getClass());
}

代码示例来源:origin: spring-projects/spring-framework

public Jackson2SmileEncoder(ObjectMapper mapper, MimeType... mimeTypes) {
  super(mapper, mimeTypes);
  Assert.isAssignable(SmileFactory.class, mapper.getFactory().getClass());
  setStreamingMediaTypes(Collections.singletonList(new MediaType("application", "stream+x-jackson-smile")));
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Constructor with a Jackson {@link ObjectMapper} to use.
 */
protected AbstractJackson2Decoder(ObjectMapper mapper, MimeType... mimeTypes) {
  super(mapper, mimeTypes);
  this.jsonFactory = mapper.getFactory().copy()
      .disable(JsonFactory.Feature.USE_THREAD_LOCAL_FOR_BUFFER_RECYCLING);
}

代码示例来源:origin: apache/incubator-druid

private MappingIterator<Entry<KeyType>> read(final File file, final Class<KeyType> keyClazz)
{
 try {
  return spillMapper.readValues(
    spillMapper.getFactory().createParser(new LZ4BlockInputStream(new FileInputStream(file))),
    spillMapper.getTypeFactory().constructParametricType(Entry.class, keyClazz)
  );
 }
 catch (IOException e) {
  throw Throwables.propagate(e);
 }
}

代码示例来源:origin: apache/incubator-druid

private <T> byte[] toByteArray(final Iterable<T> results) throws IOException
{
 final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
 try (JsonGenerator gen = objectMapper.getFactory().createGenerator(bytes)) {
  for (T result : results) {
   gen.writeObject(result);
  }
 }
 return bytes.toByteArray();
}

代码示例来源:origin: prestodb/presto

private static boolean isValidJson(String json)
  {
    boolean valid = false;
    try {
      JsonParser parser = new ObjectMapper().getFactory()
          .createParser(json);
      continueWhileNotNull(parser, parser.nextToken());
      valid = true;
    }
    catch (IOException ignored) {
    }
    return valid;
  }
}

代码示例来源:origin: apache/incubator-druid

private List readQueryResultArrayFromString(String str) throws Exception
{
 List result = new ArrayList();
 JsonParser jp = mapper.getFactory().createParser(str);
 if (jp.nextToken() != JsonToken.START_ARRAY) {
  throw new IAE("not an array [%s]", str);
 }
 ObjectCodec objectCodec = jp.getCodec();
 while (jp.nextToken() != JsonToken.END_ARRAY) {
  result.add(objectCodec.readValue(jp, toolChest.getResultTypeReference()));
 }
 return result;
}

代码示例来源:origin: apache/incubator-druid

@Provides @LazySingleton @Smile
 public ObjectMapper smileMapper()
 {
  final SmileFactory smileFactory = new SmileFactory();
  smileFactory.configure(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT, false);
  smileFactory.delegateToTextual(true);
  final ObjectMapper retVal = new DefaultObjectMapper(smileFactory);
  retVal.getFactory().setCodec(retVal);
  return retVal;
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-14435
public void cbor() {
  ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.cbor().build();
  assertNotNull(objectMapper);
  assertEquals(CBORFactory.class, objectMapper.getFactory().getClass());
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-14435
public void smile() {
  ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.smile().build();
  assertNotNull(objectMapper);
  assertEquals(SmileFactory.class, objectMapper.getFactory().getClass());
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-14435
public void factory() {
  ObjectMapper objectMapper = new Jackson2ObjectMapperBuilder().factory(new SmileFactory()).build();
  assertNotNull(objectMapper);
  assertEquals(SmileFactory.class, objectMapper.getFactory().getClass());
}

代码示例来源:origin: apache/incubator-druid

public ObjectMapper getSmileMapper()
{
 final SmileFactory smileFactory = new SmileFactory();
 smileFactory.configure(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT, false);
 smileFactory.delegateToTextual(true);
 final ObjectMapper retVal = new DefaultObjectMapper(smileFactory);
 retVal.getFactory().setCodec(retVal);
 return retVal;
}

代码示例来源:origin: spring-projects/spring-framework

@Test  // SPR-14435
public void setFactory() {
  this.factory.setFactory(new SmileFactory());
  this.factory.afterPropertiesSet();
  assertNotNull(this.factory.getObject());
  assertTrue(this.factory.isSingleton());
  assertEquals(SmileFactory.class, this.factory.getObject().getFactory().getClass());
}

相关文章

微信公众号

最新文章

更多

ObjectMapper类方法