use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project autorest-clientruntime-for-java by Azure.
the class Validator method validate.
/**
* Validates a user provided required parameter to be not null.
* An {@link IllegalArgumentException} is thrown if a property fails the validation.
*
* @param parameter the parameter to validate
* @throws IllegalArgumentException thrown when the Validator determines the argument is invalid
*/
public static void validate(Object parameter) {
// Validation of top level payload is done outside
if (parameter == null) {
return;
}
Class parameterType = parameter.getClass();
TypeToken<?> parameterToken = TypeToken.of(parameterType);
if (Primitives.isWrapperType(parameterType)) {
parameterToken = parameterToken.unwrap();
}
if (parameterToken.isPrimitive() || parameterType.isEnum() || parameterType == Class.class || parameterToken.isSupertypeOf(LocalDate.class) || parameterToken.isSupertypeOf(DateTime.class) || parameterToken.isSupertypeOf(String.class) || parameterToken.isSupertypeOf(DateTimeRfc1123.class) || parameterToken.isSupertypeOf(Period.class)) {
return;
}
for (Class<?> c : parameterToken.getTypes().classes().rawTypes()) {
// Ignore checks for Object type.
if (c.isAssignableFrom(Object.class)) {
continue;
}
for (Field field : c.getDeclaredFields()) {
field.setAccessible(true);
int mod = field.getModifiers();
// Skip static fields since we don't have any, skip final fields since users can't modify them
if (Modifier.isFinal(mod) || Modifier.isStatic(mod)) {
continue;
}
JsonProperty annotation = field.getAnnotation(JsonProperty.class);
// Skip read-only properties (WRITE_ONLY)
if (annotation != null && annotation.access().equals(JsonProperty.Access.WRITE_ONLY)) {
continue;
}
Object property;
try {
property = field.get(parameter);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
if (property == null) {
if (annotation != null && annotation.required()) {
throw new IllegalArgumentException(field.getName() + " is required and cannot be null.");
}
} else {
try {
Class<?> propertyType = property.getClass();
if (TypeToken.of(List.class).isSupertypeOf(propertyType)) {
List<?> items = (List<?>) property;
for (Object item : items) {
Validator.validate(item);
}
} else if (TypeToken.of(Map.class).isSupertypeOf(propertyType)) {
Map<?, ?> entries = (Map<?, ?>) property;
for (Map.Entry<?, ?> entry : entries.entrySet()) {
Validator.validate(entry.getKey());
Validator.validate(entry.getValue());
}
} else if (parameterType != propertyType) {
Validator.validate(property);
}
} catch (IllegalArgumentException ex) {
if (ex.getCause() == null) {
// Build property chain
throw new IllegalArgumentException(field.getName() + "." + ex.getMessage());
} else {
throw ex;
}
}
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project crnk-framework by crnk-project.
the class JacksonResourceFieldInformationProvider method getJsonName.
@Override
public Optional<String> getJsonName(BeanAttributeInformation attributeDesc) {
Optional<JsonProperty> ignoreAnnotation = attributeDesc.getAnnotation(JsonProperty.class);
if (ignoreAnnotation.isPresent() && !ignoreAnnotation.get().value().isEmpty()) {
return Optional.of(ignoreAnnotation.get().value());
}
Method getter = attributeDesc.getGetter();
if (getter != null) {
Optional<String> name = getName(getter);
if (name.isPresent()) {
return name;
}
}
Field field = attributeDesc.getField();
if (field != null) {
Optional<String> name = getName(field);
if (name.isPresent()) {
return name;
}
}
return Optional.empty();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project Krill by KorAP.
the class Match method getSnippetHTML.
@JsonProperty("snippet")
public String getSnippetHTML() {
if (!this._processHighlight())
return null;
if (this.processed && this.snippetHTML != null)
return this.snippetHTML;
if (DEBUG)
log.trace("Create HTML Snippet");
StringBuilder sb = new StringBuilder();
StringBuilder rightContext = new StringBuilder();
// Remember ids already defined to
// have joined elements
HashSet<String> joins = new HashSet<>(100);
// Snippet stack sizes
short start = (short) 0;
short end = this.snippetArray.size();
// Create context
sb.append("<span class=\"context-left\">");
if (this.startMore)
sb.append("<span class=\"more\"></span>");
// Set levels for highlights
FixedBitSet level = new FixedBitSet(255);
level.set(0, 255);
byte[] levelCache = new byte[255];
HighlightCombinatorElement elem;
end--;
if (end > 0) {
// First element of sorted array
elem = this.snippetArray.getFirst();
// First element is textual
if (elem.type == 0) {
sb.append(elem.toHTML(this, level, levelCache, joins));
// Move start position
start++;
}
;
sb.append("</span>");
// Last element of sorted array
elem = this.snippetArray.getLast();
// Create right context, if there is any
rightContext.append("<span class=\"context-right\">");
// Last element is textual
if (elem != null && elem.type == 0) {
rightContext.append(elem.toHTML(this, level, levelCache, joins));
// decrement end
end--;
}
;
}
;
if (this.endMore)
rightContext.append("<span class=\"more\"></span>");
rightContext.append("</span>");
// Iterate through all remaining elements
sb.append("<span class=\"match\">");
for (short i = start; i <= end; i++) {
elem = this.snippetArray.get(i);
// UNTESTED
if (elem != null) {
String elemString = elem.toHTML(this, level, levelCache, joins);
if (DEBUG) {
log.trace("Add node {}", elemString);
}
;
sb.append(elemString);
}
}
;
sb.append("</span>");
sb.append(rightContext);
return (this.snippetHTML = sb.toString());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project candlepin by candlepin.
the class CandlepinSwaggerModelConverter method parseProperty.
private void parseProperty(ModelConverterContext context, boolean isNested, final BeanDescription beanDesc, Set<String> propertiesToIgnore, List<Property> props, BeanPropertyDefinition propDef) {
Property property = null;
String propName = propDef.getName();
Annotation[] annotations = null;
propName = getPropName(propDef, propName);
PropertyMetadata md = propDef.getMetadata();
boolean hasSetter = false, hasGetter = false;
if (propDef.getSetter() == null) {
hasSetter = false;
} else {
hasSetter = true;
}
if (propDef.getGetter() != null) {
JsonProperty pd = propDef.getGetter().getAnnotation(JsonProperty.class);
if (pd != null) {
hasGetter = true;
}
}
Boolean isReadOnly = null;
if (!hasSetter & hasGetter) {
isReadOnly = Boolean.TRUE;
} else {
isReadOnly = Boolean.FALSE;
}
final AnnotatedMember member = propDef.getPrimaryMember();
if (member != null && !propertiesToIgnore.contains(propName) && /**
* If the owning type is nested than we should include only those
* fields that have the Hateoas annotation.
*/
!(isNested && !member.hasAnnotation(HateoasInclude.class))) {
List<Annotation> annotationList = new ArrayList<>();
for (Annotation a : member.annotations()) {
annotationList.add(a);
}
annotations = annotationList.toArray(new Annotation[annotationList.size()]);
ApiModelProperty mp = member.getAnnotation(ApiModelProperty.class);
if (mp != null && mp.readOnly()) {
isReadOnly = mp.readOnly();
}
Type nested = null;
JavaType propType = member.getType(beanDesc.bindingsForBeanType());
JsonFilter jsonFilter = propType.getRawClass().getAnnotation(JsonFilter.class);
/**
* At this point the propType is a type of some nested field of the
* type that is being processed. The condition checks if this
* particular type should have Hateoas serialization enabled. In
* other words, if we should create a new Nested* model.
*/
if (jsonFilter != null && (jsonFilter.value().equals("ConsumerFilter") || jsonFilter.value().equals("EntitlementFilter") || jsonFilter.value().equals("OwnerFilter") || jsonFilter.value().equals("GuestFilter"))) {
if (!nestedJavaTypes.containsKey(propType)) {
nestedJavaTypes.put(propType, new NestedComplexType(propType));
}
nested = nestedJavaTypes.get(propType);
} else {
nested = propType;
}
// allow override of name from annotation
if (mp != null && !mp.name().isEmpty()) {
propName = mp.name();
}
if (mp != null && !mp.dataType().isEmpty()) {
property = resolveApiAnnotated(context, property, annotations, mp, propType);
}
// no property from override, construct from propType
if (property == null) {
if (mp != null && StringUtils.isNotEmpty(mp.reference())) {
property = new RefProperty(mp.reference());
} else if (member.getAnnotation(JsonIdentityInfo.class) != null) {
property = GeneratorWrapper.processJsonIdentity(propType, context, pMapper, member.getAnnotation(JsonIdentityInfo.class), member.getAnnotation(JsonIdentityReference.class));
}
if (property == null) {
property = context.resolveProperty(nested, annotations);
}
}
if (property != null) {
addMetadataToProperty(property, propName, md, isReadOnly, member, mp);
applyBeanValidatorAnnotations(property, annotations);
props.add(property);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonProperty in project phoenicis by PhoenicisOrg.
the class LocalisationHelper method fetchParameterName.
private String fetchParameterName(Parameter parameter) {
final JsonProperty jsonAnnotation = parameter.getAnnotation(JsonProperty.class);
final ParameterName parameterNameAnnotation = parameter.getAnnotation(ParameterName.class);
if (parameterNameAnnotation != null) {
return parameterNameAnnotation.value();
}
if (jsonAnnotation != null) {
return jsonAnnotation.value();
}
return parameter.getName();
}
Aggregations