Java Code Examples for com.fasterxml.jackson.core.JsonParser#Feature

The following examples show how to use com.fasterxml.jackson.core.JsonParser#Feature . 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: Jackson2ObjectMapperBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private void configureFeature(ObjectMapper objectMapper, Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationFeature) {
		objectMapper.configure((SerializationFeature) feature, enabled);
	}
	else if (feature instanceof DeserializationFeature) {
		objectMapper.configure((DeserializationFeature) feature, enabled);
	}
	else if (feature instanceof MapperFeature) {
		objectMapper.configure((MapperFeature) feature, enabled);
	}
	else {
		throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
Example 2
Source File: Jackson2ObjectMapperBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
private void configureFeature(ObjectMapper objectMapper, Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationFeature) {
		objectMapper.configure((SerializationFeature) feature, enabled);
	}
	else if (feature instanceof DeserializationFeature) {
		objectMapper.configure((DeserializationFeature) feature, enabled);
	}
	else if (feature instanceof MapperFeature) {
		objectMapper.configure((MapperFeature) feature, enabled);
	}
	else {
		throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
Example 3
Source File: MapperBuilder.java    From qconfig with MIT License 6 votes vote down vote up
private static void configure(ObjectMapper om, Object feature, boolean state) {
    if (feature instanceof SerializationFeature)
        om.configure((SerializationFeature) feature, state);
    else if (feature instanceof DeserializationFeature)
        om.configure((DeserializationFeature) feature, state);
    else if (feature instanceof JsonParser.Feature)
        om.configure((JsonParser.Feature) feature, state);
    else if (feature instanceof JsonGenerator.Feature)
        om.configure((JsonGenerator.Feature) feature, state);
    else if (feature instanceof MapperFeature)
        om.configure((MapperFeature) feature, state);
    else if (feature instanceof Include) {
        if (state) {
            om.setSerializationInclusion((Include) feature);
        }
    }
}
 
Example 4
Source File: Jackson2ObjectMapperBuilder.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void configureFeature(ObjectMapper objectMapper, Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationFeature) {
		objectMapper.configure((SerializationFeature) feature, enabled);
	}
	else if (feature instanceof DeserializationFeature) {
		objectMapper.configure((DeserializationFeature) feature, enabled);
	}
	else if (feature instanceof MapperFeature) {
		objectMapper.configure((MapperFeature) feature, enabled);
	}
	else {
		throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
Example 5
Source File: Jackson2ObjectMapperBuilder.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private void configureFeature(ObjectMapper objectMapper, Object feature, boolean enabled) {
	if (feature instanceof JsonParser.Feature) {
		objectMapper.configure((JsonParser.Feature) feature, enabled);
	}
	else if (feature instanceof JsonGenerator.Feature) {
		objectMapper.configure((JsonGenerator.Feature) feature, enabled);
	}
	else if (feature instanceof SerializationFeature) {
		objectMapper.configure((SerializationFeature) feature, enabled);
	}
	else if (feature instanceof DeserializationFeature) {
		objectMapper.configure((DeserializationFeature) feature, enabled);
	}
	else if (feature instanceof MapperFeature) {
		objectMapper.configure((MapperFeature) feature, enabled);
	}
	else {
		throw new FatalBeanException("Unknown feature class: " + feature.getClass().getName());
	}
}
 
Example 6
Source File: MapperBuilder.java    From codehelper.generator with Apache License 2.0 6 votes vote down vote up
private static void configure(ObjectMapper om, Object feature, boolean state) {
    if (feature instanceof SerializationFeature)
        om.configure((SerializationFeature) feature, state);
    else if (feature instanceof DeserializationFeature)
        om.configure((DeserializationFeature) feature, state);
    else if (feature instanceof JsonParser.Feature)
        om.configure((JsonParser.Feature) feature, state);
    else if (feature instanceof JsonGenerator.Feature)
        om.configure((JsonGenerator.Feature) feature, state);
    else if (feature instanceof MapperFeature)
        om.configure((MapperFeature) feature, state);
    else if (feature instanceof Include) {
        if (state) {
            om.setSerializationInclusion((Include) feature);
        }
    }
}
 
Example 7
Source File: JacksonRepresentationImpl.java    From ontopia with Apache License 2.0 5 votes vote down vote up
@Override
protected ObjectMapper createObjectMapper() {
	ObjectMapper mapper = super.createObjectMapper();
	mapper.addMixInAnnotations(LocatorIF.class, MLocator.class);
	mapper.addMixInAnnotations(TopicIF.class, MTopic.class);
	mapper.addMixInAnnotations(TopicNameIF.class, MTopicName.class);
	mapper.addMixInAnnotations(VariantNameIF.class, MVariantName.class);
	mapper.addMixInAnnotations(OccurrenceIF.class, MOccurrence.class);
	mapper.addMixInAnnotations(AssociationIF.class, MAssociation.class);
	mapper.addMixInAnnotations(AssociationRoleIF.class, MAssociationRole.class);
	mapper.addMixInAnnotations(TopicMapIF.class, MTopicMapAsValue.class);
	mapper.addMixInAnnotations(TopicMapReferenceIF.class, MTopicMapReference.class);
	mapper.addMixInAnnotations(TopicMapSourceIF.class, MTopicMapSource.class);
	
	@SuppressWarnings("unchecked")
	Map<Class<?>, Class<?>> additional = (Map<Class<?>, Class<?>>) Response.getCurrent().getAttributes().get(ADDITIONAL_MIXINS_ATTRIBUTE);

	if ((additional != null) && (!additional.isEmpty())) {
		for (Map.Entry<Class<?>, Class<?>> entry : additional.entrySet()) {
			mapper.addMixInAnnotations(entry.getKey(), entry.getValue());
		}
	}
	
	for (JsonParser.Feature feature : JsonParser.Feature.values()) {
		Parameter parameter = ContextUtils.getParameter(ContextUtils.getCurrentApplicationContext(), JSONPARSER_FEATURE + feature.name());
		if (parameter != null) {
			mapper.configure(feature, ContextUtils.getParameterAsBoolean(parameter, feature.enabledByDefault() || DEFAULT_PARSER_FEATURES.contains(feature)));
		}
	}
	
	return mapper;
}