Search in sources :

Example 1 with PolymorphicStoredAsJsonBean

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

the class StoredAsJsonTest method testPolymorphicStoredAsJsonBeans.

@Test
public void testPolymorphicStoredAsJsonBeans() throws JsonProcessingException {
    PolymorphicStoredAsJsonBean bean = new PolymorphicStoredAsJsonBean();
    bean.setAnnotatedField(new PolymorphicBeanA());
    JsonNode node = Rosetta.getMapper().valueToTree(bean);
    assertThat(node.get("annotatedField")).isNotNull();
    assertThat(node.get("annotatedField").hasNonNull("beanType"));
    assertThat(Rosetta.getMapper().treeToValue(node, PolymorphicStoredAsJsonBean.class).getAnnotatedField()).isInstanceOf(PolymorphicBeanA.class);
}
Also used : PolymorphicStoredAsJsonBean(com.hubspot.rosetta.beans.PolymorphicStoredAsJsonBean) PolymorphicBeanA(com.hubspot.rosetta.beans.PolymorphicBeanA) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 2 with PolymorphicStoredAsJsonBean

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

the class StoredAsJsonTest method testNullPolymorphicStoredAsJsonBean.

@Test
public void testNullPolymorphicStoredAsJsonBean() {
    PolymorphicStoredAsJsonBean bean = new PolymorphicStoredAsJsonBean();
    bean.setAnnotatedField(new NullPolymorphicBean());
    JsonNode node = Rosetta.getMapper().valueToTree(bean);
    assertThat(node.get("annotatedField")).isNotNull();
    assertThat(node.get("annotatedField").isNull()).isTrue();
}
Also used : NullPolymorphicBean(com.hubspot.rosetta.beans.NullPolymorphicBean) PolymorphicStoredAsJsonBean(com.hubspot.rosetta.beans.PolymorphicStoredAsJsonBean) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 PolymorphicStoredAsJsonBean (com.hubspot.rosetta.beans.PolymorphicStoredAsJsonBean)2 Test (org.junit.Test)2 NullPolymorphicBean (com.hubspot.rosetta.beans.NullPolymorphicBean)1 PolymorphicBeanA (com.hubspot.rosetta.beans.PolymorphicBeanA)1