use of com.fasterxml.jackson.databind.PropertyNamingStrategy in project spring-framework by spring-projects.
the class Jackson2ObjectMapperBuilderTests method propertyNamingStrategy.
@Test
void propertyNamingStrategy() {
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().propertyNamingStrategy(strategy).build();
assertThat(objectMapper.getSerializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
assertThat(objectMapper.getDeserializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
}
use of com.fasterxml.jackson.databind.PropertyNamingStrategy in project alien4cloud by alien4cloud.
the class PropertyConstraintDeserializer method deserialize.
@Override
public PropertyConstraint deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException {
ObjectMapper mapper = (ObjectMapper) jp.getCodec();
ObjectNode node = mapper.readTree(jp);
String constraintName = null;
Iterator<String> fieldIterator = node.fieldNames();
// First field is also the constraint name ?
if (fieldIterator.hasNext()) {
constraintName = fieldIterator.next();
} else {
throw JsonMappingException.from(jp, "Constraint definition must contain one field");
}
PropertyNamingStrategy namingStrategy = mapper.getDeserializationConfig().getPropertyNamingStrategy();
Map<String, Class<? extends PropertyConstraint>> constraintsMapping = getTranslatedConstraintsMap(namingStrategy);
if (!constraintsMapping.containsKey(constraintName)) {
if ("rangeMinValue".equals(constraintName) || "rangeMaxValue".equals(constraintName)) {
return mapper.treeToValue(node, InRangeConstraint.class);
} else {
throw JsonMappingException.from(jp, "Constraint not found [" + constraintName + "], expect one of [" + this.constraints.keySet() + "]");
}
}
Class<? extends PropertyConstraint> constraintClass = constraintsMapping.get(constraintName);
return mapper.treeToValue(node, constraintClass);
}
use of com.fasterxml.jackson.databind.PropertyNamingStrategy in project spring-framework by spring-projects.
the class Jackson2ObjectMapperFactoryBeanTests method propertyNamingStrategy.
@Test
public void propertyNamingStrategy() {
PropertyNamingStrategy strategy = new PropertyNamingStrategy.SnakeCaseStrategy();
this.factory.setPropertyNamingStrategy(strategy);
this.factory.afterPropertiesSet();
assertThat(this.factory.getObject().getSerializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
assertThat(this.factory.getObject().getDeserializationConfig().getPropertyNamingStrategy()).isSameAs(strategy);
}
Aggregations