use of com.fasterxml.jackson.databind.BeanProperty in project druid by druid-io.
the class WorkerBehaviorConfigTest method testSerde.
@Test
public void testSerde() throws Exception {
WorkerBehaviorConfig config = new WorkerBehaviorConfig(new FillCapacityWithAffinityWorkerSelectStrategy(new FillCapacityWithAffinityConfig(ImmutableMap.of("foo", Arrays.asList("localhost")))), new EC2AutoScaler(7, 11, new EC2EnvironmentConfig("us-east-1a", new EC2NodeData("amiid", "instanceType", 3, 5, Arrays.asList("securityGroupIds"), "keyNames", "subnetId", null, null), new StringEC2UserData("availZone", "replace", "version")), null, null));
final ObjectMapper mapper = new DefaultObjectMapper();
mapper.setInjectableValues(new InjectableValues() {
@Override
public Object findInjectableValue(Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance) {
return null;
}
});
Assert.assertEquals(config, mapper.readValue(mapper.writeValueAsBytes(config), WorkerBehaviorConfig.class));
}
use of com.fasterxml.jackson.databind.BeanProperty in project druid by druid-io.
the class EC2AutoScalerSerdeTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
objectMapper.setInjectableValues(new InjectableValues() {
@Override
public Object findInjectableValue(Object o, DeserializationContext deserializationContext, BeanProperty beanProperty, Object o1) {
return null;
}
});
final EC2AutoScaler autoScaler = objectMapper.readValue(json, EC2AutoScaler.class);
verifyAutoScaler(autoScaler);
final EC2AutoScaler roundTripAutoScaler = objectMapper.readValue(objectMapper.writeValueAsBytes(autoScaler), EC2AutoScaler.class);
verifyAutoScaler(roundTripAutoScaler);
Assert.assertEquals("Round trip equals", autoScaler, roundTripAutoScaler);
}
use of com.fasterxml.jackson.databind.BeanProperty in project torodb by torodb.
the class DescriptionFactoryWrapper method expectObjectFormat.
@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType convertedType) {
final JsonPointer jsonPointer = getJsonPointer();
return new JsonObjectFormatVisitor.Base(getProvider()) {
@Override
public void property(BeanProperty prop) throws JsonMappingException {
visitProperty(prop, false);
}
@Override
public void optionalProperty(BeanProperty prop) throws JsonMappingException {
visitProperty(prop, true);
}
private void visitProperty(BeanProperty prop, boolean optional) throws JsonMappingException {
JsonPointer propPointer = jsonPointer.append(JsonPointer.valueOf("/" + prop.getName()));
document(propPointer, prop);
SerializerProvider p = getProvider();
JsonSerializer<Object> s = p.findValueSerializer(prop.getType(), prop);
s.acceptJsonFormatVisitor(new DescriptionFactoryWrapper(DescriptionFactoryWrapper.this, propPointer, p), prop.getType());
}
};
}
use of com.fasterxml.jackson.databind.BeanProperty in project dropwizard by dropwizard.
the class ConfigurationMetadata method expectObjectFormat.
@Override
public JsonObjectFormatVisitor expectObjectFormat(JavaType type) throws JsonMappingException {
// store the pointer to the own instance
final ConfigurationMetadata thiss = this;
return new JsonObjectFormatVisitor.Base() {
@Override
public void optionalProperty(BeanProperty prop) throws JsonMappingException {
// don't run into an infinite loop with circular dependencies
if (currentDepth >= MAX_DEPTH) {
return;
}
// check if we already visited the same property
if (parentProps.contains(prop)) {
return;
}
if (prop.getAnnotation(JsonIgnore.class) != null) {
return;
}
// build the complete field path
String name = !currentPrefix.isEmpty() ? currentPrefix + "." + prop.getName() : prop.getName();
// set state for the recursive traversal
int oldFieldSize = fields.size();
String oldPrefix = currentPrefix;
currentPrefix = name;
currentDepth++;
// the type of the field
JavaType fieldType = prop.getType();
// to the path
if (fieldType.isCollectionLikeType() || fieldType.isArrayType()) {
fieldType = fieldType.getContentType();
currentPrefix += "[*]";
}
// get the type deserializer
TypeDeserializer typeDeserializer = mapper.getDeserializationConfig().findTypeDeserializer(fieldType);
// get the default impl if available
Class<?> defaultImpl = typeDeserializer != null ? typeDeserializer.getDefaultImpl() : null;
// remember current property
parentProps.add(prop);
// visit the type of the property (or its defaultImpl).
try {
mapper.acceptJsonFormatVisitor(defaultImpl == null ? fieldType.getRawClass() : defaultImpl, thiss);
} catch (NoClassDefFoundError | TypeNotPresentException e) {
// that case, just ignore the default implementation
if (defaultImpl != null) {
return;
} else {
// implementation, so re-throw it
throw e;
}
} finally {
// reset state after the recursive traversal
parentProps.remove(prop);
currentDepth--;
currentPrefix = oldPrefix;
}
// if no new fields are discovered, we assume that we are at an primitive field
if (oldFieldSize == fields.size()) {
fields.put(name, prop.getType());
}
}
};
}
use of com.fasterxml.jackson.databind.BeanProperty in project beam by apache.
the class PipelineOptionsFactory method computeCustomSerializerForMethod.
private static Optional<JsonSerializer<Object>> computeCustomSerializerForMethod(Method method) {
try {
BeanProperty prop = createBeanProperty(method);
AnnotatedMember annotatedMethod = prop.getMember();
Object maybeSerializerClass = SERIALIZER_PROVIDER.getAnnotationIntrospector().findSerializer(annotatedMethod);
return Optional.fromNullable(SERIALIZER_PROVIDER.serializerInstance(annotatedMethod, maybeSerializerClass));
} catch (JsonMappingException e) {
throw new RuntimeException(e);
}
}
Aggregations