use of io.crnk.core.engine.information.bean.BeanInformation in project crnk-framework by crnk-project.
the class ActivitiResourceMapper method copyStaticField.
private void copyStaticField(Object resource, String attributeName, Optional<Object> activitiBean, boolean toResource) {
PreconditionUtil.assertNotNull("cannot process nested holder structures", activitiBean);
// map fields
if (activitiBean.isPresent()) {
BeanInformation activitiBeanInformation = BeanInformation.get(activitiBean.get().getClass());
if (toResource) {
Object value = PropertyUtils.getProperty(activitiBean.get(), attributeName);
PropertyUtils.setProperty(resource, attributeName, mapValue(value));
} else {
BeanAttributeInformation attribute = activitiBeanInformation.getAttribute(attributeName);
if (attribute != null && attribute.getSetter() != null) {
Object value = PropertyUtils.getProperty(resource, attributeName);
PropertyUtils.setProperty(activitiBean.get(), attributeName, unmapValue(value));
}
}
}
}
use of io.crnk.core.engine.information.bean.BeanInformation in project crnk-framework by crnk-project.
the class ResourceInformationProviderBase method getResourceFields.
protected List<ResourceField> getResourceFields(Class<?> resourceClass) {
BeanInformation beanDesc = BeanInformation.get(resourceClass);
List<String> attributeNames = beanDesc.getAttributeNames();
List<ResourceField> fields = new ArrayList<>();
Set<String> relationIdFields = new HashSet<>();
for (String attributeName : attributeNames) {
BeanAttributeInformation attributeDesc = beanDesc.getAttribute(attributeName);
if (!isIgnored(attributeDesc)) {
InformationBuilder informationBuilder = context.getInformationBuilder();
InformationBuilder.Field fieldBuilder = informationBuilder.createResourceField();
buildResourceField(beanDesc, attributeDesc, fieldBuilder);
fields.add(fieldBuilder.build());
} else if (attributeDesc.getAnnotation(JsonApiRelationId.class).isPresent()) {
relationIdFields.add(attributeDesc.getName());
}
}
verifyRelationIdFields(resourceClass, relationIdFields, fields);
return fields;
}
use of io.crnk.core.engine.information.bean.BeanInformation in project crnk-framework by crnk-project.
the class LinksInformationSerializer method serialize.
@Override
public void serialize(LinksInformation value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
BeanInformation info = BeanInformation.get(value.getClass());
for (String attrName : info.getAttributeNames()) {
BeanAttributeInformation attribute = info.getAttribute(attrName);
Object linkValue = attribute.getValue(value);
if (linkValue != null) {
gen.writeObjectFieldStart(attrName);
if (linkValue instanceof String) {
gen.writeStringField(SerializerUtil.HREF, linkValue.toString());
} else {
gen.writeObject(linkValue);
}
gen.writeEndObject();
}
}
gen.writeEndObject();
}
Aggregations