use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.
the class StoredAsJsonTest method testAnnotatedGetterWithDefaultDeserialization.
@Test
public void testAnnotatedGetterWithDefaultDeserialization() throws JsonProcessingException {
ObjectNode node = Rosetta.getMapper().createObjectNode();
node.put("annotatedGetterWithDefault", expected);
StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
assertThat(bean.getAnnotatedGetterWithDefault().getStringProperty()).isEqualTo("value");
}
use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.
the class StoredAsJsonTest method testAnnotatedSetterWithDefaultDeserialization.
@Test
public void testAnnotatedSetterWithDefaultDeserialization() throws JsonProcessingException {
ObjectNode node = Rosetta.getMapper().createObjectNode();
node.put("annotatedSetterWithDefault", expected);
StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.
the class StoredAsJsonTest method testAnnotatedSetterWithDefaultNullDeserialization.
@Test
public void testAnnotatedSetterWithDefaultNullDeserialization() throws JsonProcessingException {
ObjectNode node = Rosetta.getMapper().createObjectNode();
node.put("annotatedSetterWithDefault", NullNode.getInstance());
StoredAsJsonBean bean = Rosetta.getMapper().treeToValue(node, StoredAsJsonBean.class);
assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.
the class RosettaBinderTest method itBindsStoredAsJsonBeanCorrectly.
@Test
public void itBindsStoredAsJsonBeanCorrectly() {
InnerBean inner = new InnerBean();
inner.setStringProperty("value");
JsonNode innerJsonNode = Rosetta.getMapper().createObjectNode().set("stringProperty", TextNode.valueOf("value"));
StoredAsJsonBean bean = new StoredAsJsonBean();
bean.setAnnotatedField(inner);
bean.setAnnotatedGetter(inner);
bean.setAnnotatedSetter(inner);
bean.setAnnotatedFieldWithDefault(inner);
bean.setAnnotatedGetterWithDefault(inner);
bean.setAnnotatedSetterWithDefault(inner);
bean.setOptionalField(Optional.of(inner));
bean.setOptionalGetter(Optional.of(inner));
bean.setOptionalSetter(Optional.of(inner));
bean.setBinaryField(inner);
bean.setBinaryFieldWithDefault(inner);
bean.setJsonNodeField(innerJsonNode);
String json = "{\"stringProperty\":\"value\"}";
List<Byte> bytes = toList(json.getBytes(StandardCharsets.UTF_8));
assertThat(bind(bean)).isEqualTo(map("annotatedField", json, "annotatedGetter", json, "annotatedSetter", json, "annotatedFieldWithDefault", json, "annotatedGetterWithDefault", json, "annotatedSetterWithDefault", json, "optionalField", json, "optionalGetter", json, "optionalSetter", json, "binaryField", bytes, "binaryFieldWithDefault", bytes, "jsonNodeField", json));
assertThat(bindWithPrefix("prefix", bean)).isEqualTo(map("prefix.annotatedField", json, "prefix.annotatedGetter", json, "prefix.annotatedSetter", json, "prefix.annotatedFieldWithDefault", json, "prefix.annotatedGetterWithDefault", json, "prefix.annotatedSetterWithDefault", json, "prefix.optionalField", json, "prefix.optionalGetter", json, "prefix.optionalSetter", json, "prefix.binaryField", bytes, "prefix.binaryFieldWithDefault", bytes, "prefix.jsonNodeField", json));
}
use of com.hubspot.rosetta.beans.StoredAsJsonBean in project Rosetta by HubSpot.
the class RosettaMapperTest method itMapsStoredAsJsonBeanCorrectly.
@Test
public void itMapsStoredAsJsonBeanCorrectly() {
String json = "{\"stringProperty\":\"value\"}";
initializeResultSet("table.annotatedField", json, "table.annotatedGetter", json, "table.annotatedSetter", json, "table.annotatedFieldWithDefault", json, "table.annotatedGetterWithDefault", json, "table.annotatedSetterWithDefault", json);
StoredAsJsonBean bean = map(StoredAsJsonBean.class);
assertThat(bean.getAnnotatedField().getStringProperty()).isEqualTo("value");
assertThat(bean.getAnnotatedGetter().getStringProperty()).isEqualTo("value");
assertThat(bean.getAnnotatedSetter().getStringProperty()).isEqualTo("value");
assertThat(bean.getAnnotatedFieldWithDefault().getStringProperty()).isEqualTo("value");
assertThat(bean.getAnnotatedGetterWithDefault().getStringProperty()).isEqualTo("value");
assertThat(bean.getAnnotatedSetterWithDefault().getStringProperty()).isEqualTo("value");
}
Aggregations