Search in sources :

Example 11 with BeanAttributeInformation

use of io.crnk.core.engine.information.bean.BeanAttributeInformation in project crnk-framework by crnk-project.

the class JacksonResourceFieldInformationProviderNamingTest method onFieldWithoutJsonPropertyShouldReturnBaseName.

@Test
public void onFieldWithoutJsonPropertyShouldReturnBaseName() throws Exception {
    BeanAttributeInformation field = beanDesc.getAttribute("field");
    assertThat(sut.getJsonName(field).isPresent()).isFalse();
}
Also used : BeanAttributeInformation(io.crnk.core.engine.information.bean.BeanAttributeInformation) Test(org.junit.Test)

Example 12 with BeanAttributeInformation

use of io.crnk.core.engine.information.bean.BeanAttributeInformation in project crnk-framework by crnk-project.

the class JacksonResourceFieldInformationProviderNamingTest method onFieldNameWithNamingStrategyShouldReturnModifiedName.

@Test
public void onFieldNameWithNamingStrategyShouldReturnModifiedName() throws Exception {
    objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
    sut = new JacksonResourceFieldInformationProvider();
    sut.init(context);
    Field field = TestClass.class.getDeclaredField("namingStrategyTest");
    String name = sut.getName(field).get();
    assertThat(name).isEqualTo("naming_strategy_test");
    BeanAttributeInformation attr = beanDesc.getAttribute("namingStrategyTest");
    assertThat(sut.getJsonName(attr).get()).isEqualTo("naming_strategy_test");
}
Also used : Field(java.lang.reflect.Field) BeanAttributeInformation(io.crnk.core.engine.information.bean.BeanAttributeInformation) Test(org.junit.Test)

Example 13 with BeanAttributeInformation

use of io.crnk.core.engine.information.bean.BeanAttributeInformation in project crnk-framework by crnk-project.

the class JacksonResourceFieldInformationProviderNamingTest method onWrappedFieldShouldReturnFieldNameBasedOnGetter.

@Test
public void onWrappedFieldShouldReturnFieldNameBasedOnGetter() throws Exception {
    BeanAttributeInformation attr = beanDesc.getAttribute("booleanProperty");
    assertThat(sut.getJsonName(attr).isPresent()).isFalse();
}
Also used : BeanAttributeInformation(io.crnk.core.engine.information.bean.BeanAttributeInformation) Test(org.junit.Test)

Aggregations

BeanAttributeInformation (io.crnk.core.engine.information.bean.BeanAttributeInformation)13 Test (org.junit.Test)9 BeanInformation (io.crnk.core.engine.information.bean.BeanInformation)3 Method (java.lang.reflect.Method)2 InformationBuilder (io.crnk.core.engine.information.InformationBuilder)1 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceFieldType (io.crnk.core.engine.information.resource.ResourceFieldType)1 JsonApiRelation (io.crnk.core.resource.annotations.JsonApiRelation)1 SerializeType (io.crnk.core.resource.annotations.SerializeType)1 Field (java.lang.reflect.Field)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1