List of usage examples for com.fasterxml.jackson.databind BeanProperty getMember
public abstract AnnotatedMember getMember();
From source file:capital.scalable.restdocs.jackson.FieldDocumentationObjectVisitor.java
private boolean shouldExpand(BeanProperty prop) { return prop.getMember().getAnnotation(RestdocsNotExpanded.class) == null; }
From source file:capital.scalable.restdocs.jackson.FieldDocumentationObjectVisitor.java
@Override public void optionalProperty(BeanProperty prop) throws JsonMappingException { String jsonName = prop.getName(); String fieldName = prop.getMember().getName(); JavaType type = prop.getType();//from w ww . ja v a2 s. co m if (type == null) { throw new IllegalStateException( "Missing type for property '" + jsonName + "', " + "field '" + fieldName + "'"); } JsonSerializer<?> ser = getSer(prop); if (ser == null) { return; } String fieldPath = path + (path.isEmpty() ? "" : ".") + jsonName; Class<?> javaBaseClass = prop.getMember().getDeclaringClass(); boolean shouldExpand = shouldExpand(prop); InternalFieldInfo fieldInfo = new InternalFieldInfo(javaBaseClass, fieldName, fieldPath, shouldExpand); JsonFormatVisitorWrapper visitor = new FieldDocumentationVisitorWrapper(getProvider(), context, fieldPath, fieldInfo); ser.acceptJsonFormatVisitor(visitor, type); }
From source file:org.hyperledger.jackson.TransactionDeserializer.java
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat(property.getMember()); if (format != null && Objects.equals(TransactionSerializer.BASE64_FORMAT, format.getPattern())) { return new Base64TransactionDeserializer(formatter); }//from www . j av a 2 s . c om } return new HexTransactionDeserializer(formatter); }
From source file:com.bitsofproof.dropwizard.supernode.jackson.TransactionDeserializer.java
@Override public JsonDeserializer<?> createContextual(DeserializationContext ctxt, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = ctxt.getAnnotationIntrospector().findFormat((Annotated) property.getMember()); if (format != null && Objects.equals(TransactionSerializer.BASE64_FORMAT, format.getPattern())) { return new Base64TransactionDeserializer(); }//from w w w.ja v a 2 s . co m } return new HexTransactionDeserializer(); }
From source file:org.hyperledger.jackson.TransactionSerializer.java
@Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat(property.getMember()); if (format != null && Objects.equals(BASE64_FORMAT, format.getPattern())) { return new Base64TransactionSerializer(); }//from www.ja v a2 s.c om } return new HexTransactionSerializer(); }
From source file:com.bitsofproof.dropwizard.supernode.jackson.TransactionSerializer.java
@Override public JsonSerializer<?> createContextual(SerializerProvider prov, BeanProperty property) throws JsonMappingException { if (property != null) { JsonFormat.Value format = prov.getAnnotationIntrospector().findFormat((Annotated) property.getMember()); if (format != null && Objects.equals(BASE64_FORMAT, format.getPattern())) { return new Base64TransactionSerializer(); }//from ww w.j a va 2 s.c o m } return new HexTransactionSerializer(); }
From source file:org.brutusin.json.impl.JacksonSchemaFactory.java
void enrich(SimpleTypeSchema schema, BeanProperty beanProperty) { JsonProperty jsonAnnot = beanProperty.getAnnotation(JsonProperty.class); IndexableProperty indexAnnot = beanProperty.getAnnotation(IndexableProperty.class); DependentProperty dependsAnnot = beanProperty.getAnnotation(DependentProperty.class); if (schema instanceof StringSchema) { StringSchema sschema = (StringSchema) schema; try {// ww w. j a v a2 s. co m Set<String> enums = sschema.getEnums(); if (enums != null) { Method method = schema.getClass().getMethod("setValues", List.class); method.invoke(schema, new ArrayList(enums)); } } catch (Exception parseException) { throw new Error("Error setting enum value from enumeration for " + beanProperty.getFullName(), parseException); } } if (jsonAnnot == null) { schema.setTitle(beanProperty.getName()); } else { if (jsonAnnot.title() != null) { schema.setTitle(jsonAnnot.title()); } else { schema.setTitle(beanProperty.getName()); } schema.setDescription(jsonAnnot.description()); schema.setRequired(jsonAnnot.required()); String def = jsonAnnot.defaultJsonExp(); if (def != null) { try { Object defaultValue = JsonCodec.getInstance().parse(def, beanProperty.getType().getRawClass()); Method method = schema.getClass().getMethod("setDef", Object.class); method.invoke(schema, defaultValue); } catch (Exception parseException) { throw new Error("Error setting default value for " + beanProperty.getFullName(), parseException); } } String valuesMethodName = jsonAnnot.valuesMethod(); if (valuesMethodName != null && !valuesMethodName.isEmpty()) { try { Method valuesMethod = beanProperty.getMember().getDeclaringClass().getMethod(valuesMethodName, null); valuesMethod.setAccessible(true); Object valuesValue = valuesMethod.invoke(null, null); Method method = schema.getClass().getMethod("setValues", List.class); method.invoke(schema, valuesValue); } catch (Exception ex) { throw new Error("Error setting enum value from @JsonProperty.valuesMethod() for " + beanProperty.getFullName(), ex); } } else { String values = jsonAnnot.values(); if (values != null && !values.isEmpty()) { try { Object valuesValue = JsonCodec.getInstance().parse(values, List.class); Method method = schema.getClass().getMethod("setValues", List.class); method.invoke(schema, valuesValue); } catch (Exception parseException) { throw new Error("Error setting enum value from @JsonProperty.values() for " + beanProperty.getFullName(), parseException); } } } } if (indexAnnot != null) { try { Method method = schema.getClass().getMethod("setIndex", IndexableProperty.IndexMode.class); method.invoke(schema, indexAnnot.mode()); } catch (Exception parseException) { throw new Error("Error setting index value for " + beanProperty.getFullName(), parseException); } } if (dependsAnnot != null) { try { Method method = schema.getClass().getMethod("setDependsOn", String[].class); method.invoke(schema, (Object) dependsAnnot.dependsOn()); } catch (Exception parseException) { throw new Error("Error setting dependsOn value for " + beanProperty.getFullName(), parseException); } } }