com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver Java Examples

The following examples show how to use com.fasterxml.jackson.databind.module.SimpleAbstractTypeResolver. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ObjectMapperProvider.java    From icure-backend with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ObjectMapper getContext(Class<?> type) {
	// TypeResolver
	SimpleAbstractTypeResolver abstractTypeResolver = new SimpleAbstractTypeResolver();
	abstractTypeResolver.addMapping(List.class, ArrayList.class);
	abstractTypeResolver.addMapping(Set.class, HashSet.class);
	abstractTypeResolver.addMapping(Map.class, HashMap.class);

	// Serializer
	DefaultSerializerProvider serializerProvider = new DefaultSerializerProvider.Impl();

	// Deserializer
	DeserializerFactoryConfig deserializerFactoryConfig = new DeserializerFactoryConfig().withAbstractTypeResolver(abstractTypeResolver);
	BeanDeserializerFactory deserializerFactory = new BeanDeserializerFactory(deserializerFactoryConfig);
	DefaultDeserializationContext.Impl deserializationContext = new DefaultDeserializationContext.Impl(deserializerFactory);

	// ObjectMapper
	ObjectMapper objectMapper = new ObjectMapper(null, serializerProvider, deserializationContext);
	objectMapper = objectMapper.enableDefaultTypingAsProperty(ObjectMapper.DefaultTyping.OBJECT_AND_NON_CONCRETE, "type");
	objectMapper = objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
	objectMapper = objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);

	return objectMapper;
}
 
Example #2
Source File: Status.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
@JsonIgnore
public List<AppStatus> getAppStatusList() {
	try {
		ObjectMapper mapper = new ObjectMapper();
		mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
		mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
		SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
		SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
		resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
		module.setAbstractTypes(resolver);
		mapper.registerModule(module);
		TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
		};
		if (this.platformStatus != null) {
			return mapper.readValue(this.platformStatus, typeRef);
		}
		return new ArrayList<AppStatus>();
	}
	catch (Exception e) {
		throw new IllegalArgumentException("Could not parse Skipper Platfrom Status JSON:" + platformStatus, e);
	}
}
 
Example #3
Source File: SkipperStreamDeployer.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
public static List<AppStatus> deserializeAppStatus(String platformStatus) {
	try {
		if (platformStatus != null) {
			ObjectMapper mapper = new ObjectMapper();
			mapper.addMixIn(AppStatus.class, AppStatusMixin.class);
			mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
			SimpleModule module = new SimpleModule("CustomModel", Version.unknownVersion());
			SimpleAbstractTypeResolver resolver = new SimpleAbstractTypeResolver();
			resolver.addMapping(AppInstanceStatus.class, AppInstanceStatusImpl.class);
			module.setAbstractTypes(resolver);
			mapper.registerModule(module);
			TypeReference<List<AppStatus>> typeRef = new TypeReference<List<AppStatus>>() {
			};
			return mapper.readValue(platformStatus, typeRef);
		}
		return new ArrayList<>();
	}
	catch (Exception e) {
		logger.error("Could not parse Skipper Platform Status JSON [" + platformStatus + "]. " +
				"Exception message = " + e.getMessage());
		return new ArrayList<>();
	}
}