本文整理汇总了Java中com.fasterxml.jackson.databind.type.SimpleType类的典型用法代码示例。如果您正苦于以下问题:Java SimpleType类的具体用法?Java SimpleType怎么用?Java SimpleType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleType类属于com.fasterxml.jackson.databind.type包,在下文中一共展示了SimpleType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initPropertyMap
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
private static void initPropertyMap() {
PROPERTY_MAP.put(BooleanProperty.class, SimpleType.constructUnsafe(Boolean.class));
PROPERTY_MAP.put(FloatProperty.class, SimpleType.constructUnsafe(Float.class));
PROPERTY_MAP.put(DoubleProperty.class, SimpleType.constructUnsafe(Double.class));
PROPERTY_MAP.put(DecimalProperty.class, SimpleType.constructUnsafe(BigDecimal.class));
PROPERTY_MAP.put(ByteProperty.class, SimpleType.constructUnsafe(Byte.class));
PROPERTY_MAP.put(ShortProperty.class, SimpleType.constructUnsafe(Short.class));
PROPERTY_MAP.put(IntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
PROPERTY_MAP.put(BaseIntegerProperty.class, SimpleType.constructUnsafe(Integer.class));
PROPERTY_MAP.put(LongProperty.class, SimpleType.constructUnsafe(Long.class));
// stringProperty包含了enum的场景,并不一定是转化为string
// 但是,如果统一走StringPropertyConverter则可以处理enum的场景
PROPERTY_MAP.put(StringProperty.class, SimpleType.constructUnsafe(String.class));
PROPERTY_MAP.put(DateProperty.class, SimpleType.constructUnsafe(LocalDate.class));
PROPERTY_MAP.put(DateTimeProperty.class, SimpleType.constructUnsafe(Date.class));
PROPERTY_MAP.put(ByteArrayProperty.class, SimpleType.constructUnsafe(byte[].class));
PROPERTY_MAP.put(FileProperty.class, SimpleType.constructUnsafe(Part.class));
}
示例2: handleUnknownTypeId
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Override
public JavaType handleUnknownTypeId(final DeserializationContext ctxt, final JavaType baseType,
final String subTypeId, final TypeIdResolver idResolver,
final String failureMsg) throws IOException {
try {
if (subTypeId.contains("org.jasig.")) {
final String newTypeName = subTypeId.replaceAll("jasig", "apereo");
LOGGER.warn("Found legacy CAS JSON definition type identified as [{}]. "
+ "While CAS will attempt to convert the legacy definition to [{}] for the time being, "
+ "the definition SHOULD manually be upgraded to the new supported syntax",
subTypeId, newTypeName);
final Class newType = ClassUtils.getClass(newTypeName);
return SimpleType.construct(newType);
}
return null;
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例3: deserializeTypedFromObject
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Override
public Object deserializeTypedFromObject(final JsonParser jp, final DeserializationContext ctxt) throws IOException {
JsonNode node = jp.readValueAsTree();
NamedDefinition res = NamedProviders.get((Class<NamedDefinition>) _baseType.getRawClass(), node.get("type").asText());
if (res == null) {
return null;
}
JavaType type = SimpleType.construct(res.getClass());
JsonParser jsonParser = new TreeTraversingParser(node, jp.getCodec());
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
JsonDeserializer<Object> deser = ctxt.findContextualValueDeserializer(type, _property);
return deser.deserialize(jsonParser, ctxt);
}
示例4: typeFromId
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Override
public JavaType typeFromId(DatabindContext context, String id) {
DeserializationContext ctx = (DeserializationContext) context;
Map<String, Class> map = (Map) ctx.getAttribute("secucardobjectmap");
Class type = map.get(id);
JavaType javatype;
if (type == null) {
javatype = MapType.construct(HashMap.class, SimpleType.construct(String.class), SimpleType.construct(Object.class));
} else {
javatype = SimpleType.construct(type);
}
if (JsonToken.END_ARRAY.equals(ctx.getParser().getCurrentToken())) {
// it is expected to get called here when reading the last token.
javatype = CollectionType.construct(ArrayList.class, javatype);
}
return javatype;
}
示例5: getRepoIndex
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Override
public Set<PackageVersion> getRepoIndex(IRepoProvider provider) {
RepoEntry indexEntry = provider.getEntry(IndexFileIndexer.INDEX_FILE);
if (indexEntry != null) {
if (!indexEntry.hasChanged(this.latest)) {
return null;
}
this.latest = indexEntry;
try {
String indexString = StreamUtils.copyToString(provider.getEntryStream(IndexFileIndexer.INDEX_FILE), Charset.forName("UTF-8"));
CollectionType indexType = CollectionType.construct(Set.class, SimpleType.construct(PackageVersion.class));
return this.mapper.readValue(indexString, indexType);
} catch (IOException e) {
throw new RuntimeException("Failed to read index", e);
}
}
throw new RuntimeException("Didn't find index file");
}
示例6: getObjectMapper
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
private ObjectMapper getObjectMapper() {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
// objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
// true);
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
TypeResolverBuilder<?> joynrTypeResolverBuilder = objectMapper.getSerializationConfig()
.getDefaultTyper(SimpleType.construct(Object.class));
SimpleModule module = new SimpleModule("NonTypedModule", new Version(1, 0, 0, "", "", ""));
module.addSerializer(new JoynrEnumSerializer());
module.addSerializer(new JoynrListSerializer());
TypeDeserializer typeDeserializer = joynrTypeResolverBuilder.buildTypeDeserializer(objectMapper.getDeserializationConfig(),
SimpleType.construct(Object.class),
null);
module.addDeserializer(Object.class, new JoynrUntypedObjectDeserializer(typeDeserializer));
objectMapper.registerModule(module);
return objectMapper;
}
示例7: getObjectMapper
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
private ObjectMapper getObjectMapper() {
objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
// objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS,
// true);
objectMapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true);
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
objectMapper.enableDefaultTypingAsProperty(DefaultTyping.JAVA_LANG_OBJECT, "_typeName");
TypeResolverBuilder<?> joynrTypeResolverBuilder = objectMapper.getSerializationConfig()
.getDefaultTyper(SimpleType.construct(Object.class));
return objectMapper;
}
示例8: typeScriptTypeFromJavaType
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
private AbstractType typeScriptTypeFromJavaType(Module module, Class<?> type) {
if (type == boolean.class) {
return BooleanType.getInstance();
} else if (type == int.class) {
return NumberType.getInstance();
} else if (type == double.class) {
return NumberType.getInstance();
} else if (type == String.class) {
return StringType.getInstance();
} else if (type.isEnum()) {
return tsJsonFormatVisitorWrapper.parseEnumOrGetFromCache(module, SimpleType
.construct(type));
} else if (type.isArray()) {
return new ArrayType(AnyType.getInstance());
}
throw new UnsupportedOperationException();
}
示例9: generateTypeScript
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
/**
* @param module
* Module to be filled with named types (classes, enums, ...)
* @param classes
* Class for which generating definition
* @throws JsonMappingException
*/
public Module generateTypeScript(String moduleName, Collection<? extends Class<?>> classes, Configuration conf)
throws JsonMappingException {
if(conf == null) {
conf = new Configuration();
}
Module module = new Module(moduleName);
TSJsonFormatVisitorWrapper visitor = new TSJsonFormatVisitorWrapper(module, conf);
for (Class<?> clazz : classes) {
AbstractType customType = conf.getCustomTypes().get(clazz.getName());
if(customType != null && customType instanceof TypeDeclarationType) {
// When the class is registered as TypeDeclarationType, then ...
String tsTypeName = conf.getNamingStrategy().getName(SimpleType.construct(clazz));
// ... add that type to the module ...
module.getNamedTypes().put(tsTypeName, (TypeDeclarationType)customType);
// ... instead of inspecting class body
continue;
}
mapper.acceptJsonFormatVisitor(clazz, visitor);
}
return module;
}
示例10: modules
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Test
public void modules() {
NumberSerializer serializer1 = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer1);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modules(module).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer1, serializers.findSerializer(null, SimpleType.construct(Integer.class), null));
}
示例11: modulesToInstallByClass
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void modulesToInstallByClass() {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().modulesToInstall(CustomIntegerModule.class).build();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(CustomIntegerSerializer.class, serializers.findSerializer(null, SimpleType.construct(Integer.class), null).getClass());
}
示例12: serializerByType
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Test
public void serializerByType() {
JsonSerializer<Number> serializer = new NumberSerializer(Integer.class);
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.serializerByType(Boolean.class, serializer).build();
assertTrue(getSerializerFactoryConfig(objectMapper).hasSerializers());
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Boolean.class), null));
}
示例13: deserializerByType
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Test
public void deserializerByType() throws JsonMappingException {
JsonDeserializer<Date> deserializer = new DateDeserializers.DateDeserializer();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json()
.modules(new ArrayList<>()) // Disable well-known modules detection
.deserializerByType(Date.class, deserializer).build();
assertTrue(getDeserializerFactoryConfig(objectMapper).hasDeserializers());
Deserializers deserializers = getDeserializerFactoryConfig(objectMapper).deserializers().iterator().next();
assertSame(deserializer, deserializers.findBeanDeserializer(SimpleType.construct(Date.class), null, null));
}
示例14: setModules
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Test
public void setModules() {
NumberSerializer serializer = new NumberSerializer(Integer.class);
SimpleModule module = new SimpleModule();
module.addSerializer(Integer.class, serializer);
this.factory.setModules(Arrays.asList(new Module[]{module}));
this.factory.afterPropertiesSet();
ObjectMapper objectMapper = this.factory.getObject();
Serializers serializers = getSerializerFactoryConfig(objectMapper).serializers().iterator().next();
assertSame(serializer, serializers.findSerializer(null, SimpleType.construct(Integer.class), null));
}
示例15: setupModule
import com.fasterxml.jackson.databind.type.SimpleType; //导入依赖的package包/类
@Override
public void setupModule(SetupContext context) {
// Modify the Map serializer to the delegate if it matches Map<String, ?>
context.addBeanSerializerModifier(new BeanSerializerModifier() {
@Override
public JsonSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType, BeanDescription beanDesc,
JsonSerializer<?> serializer) {
if (valueType.getKeyType().equals(SimpleType.construct(String.class))) {
return new DelegatingMapSerializer(serializer);
}
return serializer;
}
});
}