Esempio n. 1
0
  @Test
  public void testLoadTwoRootObjectsWithNoType() throws JsonProcessingException {
    JsonNode data =
        mapper
            .createArrayNode()
            .add(
                mapper.createObjectNode().put("userId", "1").put("name", "Paul").put("sex", "MALE"))
            .add(
                mapper
                    .createObjectNode()
                    .put("userId", "2")
                    .put("name", "Anna")
                    .put("sex", "FEMALE"));

    Resource result =
        mapper
            .reader()
            .withAttribute(RESOURCE_SET, resourceSet)
            .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER)
            .treeToValue(data, Resource.class);

    assertNotNull(result);
    assertEquals(2, result.getContents().size());

    User first = (User) result.getContents().get(0);
    User second = (User) result.getContents().get(1);

    assertEquals("1", first.getUserId());
    assertEquals("Paul", first.getName());
    assertEquals("MALE", first.getSex().getLiteral());

    assertEquals("2", second.getUserId());
    assertEquals("Anna", second.getName());
    assertEquals("FEMALE", second.getSex().getLiteral());
  }
Esempio n. 2
0
  @Test
  public void testLoadSingleObjectWithNoType() throws JsonProcessingException {
    JsonNode data = mapper.createObjectNode().put("userId", "1").put("name", "Paul");

    User result =
        mapper
            .reader()
            .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER)
            .treeToValue(data, User.class);

    assertNotNull(result);

    assertEquals("1", result.getUserId());
    assertEquals("Paul", result.getName());
    assertEquals("MALE", result.getSex().getLiteral());
  }
Esempio n. 3
0
  @Test
  public void testLoadSingleObjectWithNoTypeAndOneContainment() throws JsonProcessingException {
    JsonNode data =
        mapper
            .createObjectNode()
            .put("userId", "1")
            .put("name", "Paul")
            .set("address", mapper.createObjectNode().put("addId", "a1").put("city", "Prague"));

    User result =
        mapper
            .reader()
            .withAttribute(RESOURCE_SET, resourceSet)
            .withAttribute(ROOT_ELEMENT, ModelPackage.Literals.USER)
            .treeToValue(data, User.class);

    assertNotNull(result);

    assertEquals("1", result.getUserId());
    assertEquals("Paul", result.getName());
    assertEquals("MALE", result.getSex().getLiteral());

    assertNotNull(result.getAddress());
  }