本文整理汇总了Java中com.fasterxml.jackson.databind.cfg.HandlerInstantiator类的典型用法代码示例。如果您正苦于以下问题:Java HandlerInstantiator类的具体用法?Java HandlerInstantiator怎么用?Java HandlerInstantiator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HandlerInstantiator类属于com.fasterxml.jackson.databind.cfg包,在下文中一共展示了HandlerInstantiator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createInstantiatesObjectMapperWithInlineAssociationDeserializerAwareHandlerInstantiator
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Test
public void createInstantiatesObjectMapperWithInlineAssociationDeserializerAwareHandlerInstantiator() {
ObjectMapper mapper = new ObjectMapper();
RestTemplate restTemplate = new RestTemplate();
when(mapperFactory.create(any(HandlerInstantiator.class))).thenReturn(mapper);
when(restTemplateFactory.create(any(ClientHttpRequestFactory.class), any(ObjectMapper.class)))
.thenReturn(restTemplate);
factory.create();
ArgumentCaptor<HandlerInstantiator> handlerInstantiator = ArgumentCaptor.forClass(HandlerInstantiator.class);
verify(mapperFactory).create(handlerInstantiator.capture());
assertThat(handlerInstantiator.getValue().deserializerInstance(null, null, InlineAssociationDeserializer.class),
is(anInlineAssociationDeserializerMatching(aRestOperationsMatching(restTemplate, mapper),
proxyFactory)));
}
示例2: createInvokesConfigurerOnObjectMapperIfPresent
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Test
public void createInvokesConfigurerOnObjectMapperIfPresent() {
ObjectMapperConfigurer objectMapperConfigurer = mock(ObjectMapperConfigurer.class);
Configuration configuration = Configuration.builder()
.setObjectMapperConfigurer(objectMapperConfigurer)
.build();
ObjectMapper objectMapper = new ObjectMapper();
when(mapperFactory.create(any(HandlerInstantiator.class)))
.thenReturn(objectMapper);
new RestOperationsFactory(configuration, proxyFactory, mapperFactory, restTemplateFactory)
.create();
verify(objectMapperConfigurer).configure(objectMapper);
}
示例3: setup
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Before
public void setup() {
typeResolver = mock(TypeResolver.class);
configuration = Configuration.build();
instantiator = mock(HandlerInstantiator.class);
doReturn(new ResourceDeserializer(Object.class, typeResolver, configuration))
.when(instantiator).deserializerInstance(any(DeserializationConfig.class),
any(Annotated.class), eq(ResourceDeserializer.class));
mapper = new ObjectMapper();
mapper.setHandlerInstantiator(instantiator);
mapper.registerModule(new Jackson2HalModule());
mapper.registerModule(new TestModule());
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
示例4: _findNamingStrategy
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
private PropertyNamingStrategy _findNamingStrategy()
{
Object localObject1;
if (this._annotationIntrospector == null)
localObject1 = null;
else
localObject1 = this._annotationIntrospector.findNamingStrategy(this._classDef);
Object localObject2 = localObject1;
if (localObject1 == null)
return this._config.getPropertyNamingStrategy();
if ((localObject2 instanceof PropertyNamingStrategy))
return (PropertyNamingStrategy)localObject2;
if (!(localObject2 instanceof Class))
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type " + localObject2.getClass().getName() + "; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
Class localClass = (Class)localObject2;
if (!PropertyNamingStrategy.class.isAssignableFrom(localClass))
throw new IllegalStateException("AnnotationIntrospector returned Class " + localClass.getName() + "; expected Class<PropertyNamingStrategy>");
HandlerInstantiator localHandlerInstantiator = this._config.getHandlerInstantiator();
if (localHandlerInstantiator != null)
{
PropertyNamingStrategy localPropertyNamingStrategy = localHandlerInstantiator.namingStrategyInstance(this._config, this._classDef, localClass);
if (localPropertyNamingStrategy != null)
return localPropertyNamingStrategy;
}
return (PropertyNamingStrategy)ClassUtil.createInstance(localClass, this._config.canOverrideAccessModifiers());
}
示例5: _valueInstantiatorInstance
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
public ValueInstantiator _valueInstantiatorInstance(DeserializationConfig paramDeserializationConfig, Annotated paramAnnotated, Object paramObject)
{
if (paramObject == null)
return null;
if ((paramObject instanceof ValueInstantiator))
return (ValueInstantiator)paramObject;
if (!(paramObject instanceof Class))
throw new IllegalStateException("AnnotationIntrospector returned key deserializer definition of type " + paramObject.getClass().getName() + "; expected type KeyDeserializer or Class<KeyDeserializer> instead");
Class localClass = (Class)paramObject;
if (localClass == NoClass.class)
return null;
if (!ValueInstantiator.class.isAssignableFrom(localClass))
throw new IllegalStateException("AnnotationIntrospector returned Class " + localClass.getName() + "; expected Class<ValueInstantiator>");
HandlerInstantiator localHandlerInstantiator = paramDeserializationConfig.getHandlerInstantiator();
if (localHandlerInstantiator != null)
{
ValueInstantiator localValueInstantiator = localHandlerInstantiator.valueInstantiatorInstance(paramDeserializationConfig, paramAnnotated, localClass);
if (localValueInstantiator != null)
return localValueInstantiator;
}
return (ValueInstantiator)ClassUtil.createInstance(localClass, paramDeserializationConfig.canOverrideAccessModifiers());
}
示例6: objectIdGeneratorInstance
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Override
public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated,
ObjectIdInfo objectIdInfo)
throws JsonMappingException
{
Class<?> implClass = objectIdInfo.getGeneratorType();
HandlerInstantiator hi = _config.getHandlerInstantiator();
ObjectIdGenerator<?> gen;
if (hi != null) {
gen = hi.objectIdGeneratorInstance(_config, annotated, implClass);
} else {
gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass,
_config.canOverrideAccessModifiers());
}
return gen.forScope(objectIdInfo.getScope());
}
示例7: objectIdGeneratorInstance
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Override
public ObjectIdGenerator<?> objectIdGeneratorInstance(Annotated annotated,
ObjectIdInfo objectIdInfo)
throws JsonMappingException
{
Class<?> implClass = objectIdInfo.getGeneratorType();
HandlerInstantiator hi = _config.getHandlerInstantiator();
ObjectIdGenerator<?> gen;
if (hi != null) {
gen = hi.objectIdGeneratorInstance(_config, annotated, implClass);
} else {
gen = (ObjectIdGenerator<?>) ClassUtil.createInstance(implClass,
_config.canOverrideAccessModifiers());
}
return gen.forScope(objectIdInfo.getScope());
}
示例8: jacksonBuilder
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
/**
* Needed to override JSON De-/Serializer in Jackson.
*
* @param handlerInstantiator
* @return
*/
@Bean
public Jackson2ObjectMapperBuilder jacksonBuilder(HandlerInstantiator handlerInstantiator) {
Jackson2ObjectMapperBuilder b = new Jackson2ObjectMapperBuilder();
b.indentOutput(true).mixIn(Workbasket.class, WorkbasketMixIn.class);
b.handlerInstantiator(handlerInstantiator);
return b;
}
示例9: create
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Override
public ObjectMapper create(HandlerInstantiator instantiator) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new Jackson2HalModule());
mapper.registerModule(new JacksonClientModule());
mapper.setHandlerInstantiator(instantiator);
return mapper;
}
示例10: createReturnsRestOperations
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Test
public void createReturnsRestOperations() {
ObjectMapper mapper = new ObjectMapper();
RestTemplate restTemplate = new RestTemplate();
when(mapperFactory.create(any(HandlerInstantiator.class))).thenReturn(mapper);
when(restTemplateFactory.create(clientHttpRequestFactory, mapper)).thenReturn(restTemplate);
RestOperations restOperations = factory.create();
assertThat(restOperations, is(aRestOperationsMatching(restTemplate, mapper)));
}
示例11: setup
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Before
public void setup() {
RestOperations restOperations = mock(RestOperations.class);
ClientProxyFactory proxyFactory = new JavassistClientProxyFactory();
instantiator = mock(HandlerInstantiator.class);
doReturn(new InlineAssociationDeserializer<>(Object.class, restOperations, proxyFactory))
.when(instantiator).deserializerInstance(any(DeserializationConfig.class),
any(Annotated.class), eq(InlineAssociationDeserializer.class));
mapper = new ObjectMapper();
mapper.setHandlerInstantiator(instantiator);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
示例12: setup
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Before
public void setup() {
HandlerInstantiator instantiator = mock(HandlerInstantiator.class);
doReturn(declaredTypeResourceDeserializer()).when(instantiator).deserializerInstance(
any(DeserializationConfig.class), any(Annotated.class), eq(ResourceDeserializer.class));
restTemplate = mock(RestTemplate.class);
objectMapper = new DefaultObjectMapperFactory().create(instantiator);
restOperations = new RestOperations(restTemplate, objectMapper);
}
示例13: serializerInstance
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
public JsonSerializer<Object> serializerInstance(Annotated paramAnnotated, Object paramObject)
{
if (paramObject == null)
return null;
Object localObject;
if ((paramObject instanceof JsonSerializer))
{
localObject = (JsonSerializer)paramObject;
}
else
{
if (!(paramObject instanceof Class))
throw new IllegalStateException("AnnotationIntrospector returned serializer definition of type " + paramObject.getClass().getName() + "; expected type JsonSerializer or Class<JsonSerializer> instead");
Class localClass = (Class)paramObject;
if ((localClass == JsonSerializer.None.class) || (localClass == NoClass.class))
return null;
if (!JsonSerializer.class.isAssignableFrom(localClass))
throw new IllegalStateException("AnnotationIntrospector returned Class " + localClass.getName() + "; expected Class<JsonSerializer>");
HandlerInstantiator localHandlerInstantiator = this._config.getHandlerInstantiator();
JsonSerializer localJsonSerializer;
if (localHandlerInstantiator == null)
localJsonSerializer = null;
else
localJsonSerializer = localHandlerInstantiator.serializerInstance(this._config, paramAnnotated, localClass);
localObject = localJsonSerializer;
if (localJsonSerializer == null)
localObject = (JsonSerializer)ClassUtil.createInstance(localClass, this._config.canOverrideAccessModifiers());
}
return _handleResolvable((JsonSerializer)localObject);
}
示例14: serializerInstance
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
@Override
public JsonSerializer<Object> serializerInstance(Annotated annotated,
Object serDef)
throws JsonMappingException
{
if (serDef == null) {
return null;
}
JsonSerializer<?> ser;
if (serDef instanceof JsonSerializer) {
ser = (JsonSerializer<?>) serDef;
} else {
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(serDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned serializer definition of type "
+serDef.getClass().getName()+"; expected type JsonSerializer or Class<JsonSerializer> instead");
}
Class<?> serClass = (Class<?>)serDef;
// there are some known "no class" markers to consider too:
if (serClass == JsonSerializer.None.class || serClass == NoClass.class) {
return null;
}
if (!JsonSerializer.class.isAssignableFrom(serClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+serClass.getName()+"; expected Class<JsonSerializer>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
if (hi != null) {
ser = hi.serializerInstance(_config, annotated, serClass);
} else {
ser = (JsonSerializer<?>) ClassUtil.createInstance(serClass,
_config.canOverrideAccessModifiers());
}
}
return (JsonSerializer<Object>) _handleResolvable(ser);
}
示例15: _findNamingStrategy
import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; //导入依赖的package包/类
private PropertyNamingStrategy _findNamingStrategy()
{
Object namingDef = (_annotationIntrospector == null)? null
: _annotationIntrospector.findNamingStrategy(_classDef);
if (namingDef == null) {
return _config.getPropertyNamingStrategy();
}
if (namingDef instanceof PropertyNamingStrategy) {
return (PropertyNamingStrategy) namingDef;
}
/* Alas, there's no way to force return type of "either class
* X or Y" -- need to throw an exception after the fact
*/
if (!(namingDef instanceof Class)) {
throw new IllegalStateException("AnnotationIntrospector returned PropertyNamingStrategy definition of type "
+namingDef.getClass().getName()+"; expected type PropertyNamingStrategy or Class<PropertyNamingStrategy> instead");
}
Class<?> namingClass = (Class<?>)namingDef;
if (!PropertyNamingStrategy.class.isAssignableFrom(namingClass)) {
throw new IllegalStateException("AnnotationIntrospector returned Class "
+namingClass.getName()+"; expected Class<PropertyNamingStrategy>");
}
HandlerInstantiator hi = _config.getHandlerInstantiator();
if (hi != null) {
return hi.namingStrategyInstance(_config, _classDef, namingClass);
}
return (PropertyNamingStrategy) ClassUtil.createInstance(namingClass,
_config.canOverrideAccessModifiers());
}