Search in sources :

Example 1 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class RosettaBinderTest method itBindsNullStoredAsJsonBeanCorrectly.

@Test
public void itBindsNullStoredAsJsonBeanCorrectly() {
    StoredAsJsonBean bean = new StoredAsJsonBean();
    String json = "{\"stringProperty\":\"value\"}";
    List<Byte> bytes = toList(json.getBytes(StandardCharsets.UTF_8));
    assertThat(bind(bean)).isEqualTo(map("annotatedField", null, "annotatedGetter", null, "annotatedSetter", null, "annotatedFieldWithDefault", json, "annotatedGetterWithDefault", json, "annotatedSetterWithDefault", json, "optionalField", null, "optionalGetter", null, "optionalSetter", null, "binaryField", null, "binaryFieldWithDefault", bytes, "jsonNodeField", null));
    assertThat(bindWithPrefix("prefix", bean)).isEqualTo(map("prefix.annotatedField", null, "prefix.annotatedGetter", null, "prefix.annotatedSetter", null, "prefix.annotatedFieldWithDefault", json, "prefix.annotatedGetterWithDefault", json, "prefix.annotatedSetterWithDefault", json, "prefix.optionalField", null, "prefix.optionalGetter", null, "prefix.optionalSetter", null, "prefix.binaryField", null, "prefix.binaryFieldWithDefault", bytes, "prefix.jsonNodeField", null));
}
Also used : StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 2 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class RosettaMapperTest method itMapsNullStoredAsJsonBeanCorrectly.

@Test
public void itMapsNullStoredAsJsonBeanCorrectly() {
    initializeResultSet("table.annotatedField", null, "table.annotatedGetter", null, "table.annotatedSetter", null, "table.annotatedFieldWithDefault", null, "table.annotatedGetterWithDefault", null, "table.annotatedSetterWithDefault", null);
    StoredAsJsonBean bean = map(StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedField()).isNull();
    assertThat(bean.getAnnotatedGetter()).isNull();
    assertThat(bean.getAnnotatedSetter()).isNull();
    assertThat(bean.getAnnotatedFieldWithDefault().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedGetterWithDefault().getStringProperty()).isEqualTo("value");
    assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 3 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class StoredAsJsonTest method testJsonNodeFieldDeserialization.

@Test
public void testJsonNodeFieldDeserialization() throws JsonProcessingException {
    ObjectNode node = Rosetta.getMapper().createObjectNode();
    node.put("jsonNodeField", expected);
    StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
    assertThat(bean.getJsonNodeField()).isEqualTo(innerJsonNode);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 4 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class StoredAsJsonTest method testAnnotatedFieldWithDefaultNullDeserialization.

@Test
public void testAnnotatedFieldWithDefaultNullDeserialization() throws JsonProcessingException {
    ObjectNode node = Rosetta.getMapper().createObjectNode();
    node.put("annotatedFieldWithDefault", NullNode.getInstance());
    StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedFieldWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Example 5 with StoredAsJsonBean

use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.

the class StoredAsJsonTest method testAnnotatedFieldWithDefaultDeserialization.

@Test
public void testAnnotatedFieldWithDefaultDeserialization() throws JsonProcessingException {
    ObjectNode node = Rosetta.getMapper().createObjectNode();
    node.put("annotatedFieldWithDefault", expected);
    StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
    assertThat(bean.getAnnotatedFieldWithDefault().getStringProperty()).isEqualTo("value");
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StoredAsJsonBean(com.hubspot.rosetta.beans.StoredAsJsonBean) Test(org.junit.Test)

Aggregations

StoredAsJsonBean (com.hubspot.rosetta.beans.StoredAsJsonBean)29 Test (org.junit.Test)28 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)24 InnerBean (com.hubspot.rosetta.beans.InnerBean)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Before (org.junit.Before)1