use of io.crnk.core.engine.information.bean.BeanAttributeInformation in project crnk-framework by crnk-project.
the class JacksonResourceFieldInformationProviderNamingTest method onNoSerializationConfigShouldSerializeField.
@Test
public void onNoSerializationConfigShouldSerializeField() throws Exception {
sut = new JacksonResourceFieldInformationProvider();
sut.init(context);
BeanAttributeInformation field = beanDesc.getAttribute("namingStrategyTest");
assertThat(sut.getJsonName(field).isPresent()).isFalse();
}
use of io.crnk.core.engine.information.bean.BeanAttributeInformation 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.BeanAttributeInformation 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();
}
use of io.crnk.core.engine.information.bean.BeanAttributeInformation in project crnk-framework by crnk-project.
the class JacksonResourceFieldInformationProviderNamingTest method onFieldWithDefaultJsonPropertyShouldReturnBaseName.
@Test
public void onFieldWithDefaultJsonPropertyShouldReturnBaseName() throws Exception {
BeanAttributeInformation attr = beanDesc.getAttribute("fieldWithDefaultJsonProperty");
assertThat(sut.getJsonName(attr).isPresent()).isFalse();
}
use of io.crnk.core.engine.information.bean.BeanAttributeInformation in project crnk-framework by crnk-project.
the class JacksonResourceFieldInformationProviderNamingTest method onMethodNameWithNamingStrategyShouldReturnModifiedName.
@Test
public void onMethodNameWithNamingStrategyShouldReturnModifiedName() throws Exception {
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
sut = new JacksonResourceFieldInformationProvider();
sut.init(context);
Method method = TestClass.class.getDeclaredMethod("getAccessorField");
String name = sut.getName(method).get();
assertThat(name).isEqualTo("accessor_field");
BeanAttributeInformation attr = beanDesc.getAttribute("accessorField");
assertThat(sut.getJsonName(attr).get()).isEqualTo("accessor_field");
}
Aggregations