コード例 #1
0
  @Test
  public void testSaveTwoRootObjectsWithNoType() {
    JsonNode expected =
        mapper
            .createArrayNode()
            .add(mapper.createObjectNode().put("userId", "1").put("name", "Paul"))
            .add(
                mapper
                    .createObjectNode()
                    .put("userId", "2")
                    .put("name", "Anna")
                    .put("sex", "FEMALE"));

    User u1 = ModelFactory.eINSTANCE.createUser();
    u1.setUserId("1");
    u1.setName("Paul");

    User u2 = ModelFactory.eINSTANCE.createUser();
    u2.setUserId("2");
    u2.setName("Anna");
    u2.setSex(Sex.FEMALE);

    Resource resource = new JsonResource(URI.createURI("test"), mapper);
    resource.getContents().add(u1);
    resource.getContents().add(u2);

    JsonNode result = mapper.valueToTree(resource);

    assertEquals(expected, result);
  }
コード例 #2
0
  @Test
  public void testSaveSingleObjectWithNoType() {
    JsonNode expected = mapper.createObjectNode().put("userId", "1").put("name", "Paul");

    User u1 = ModelFactory.eINSTANCE.createUser();
    u1.setUserId("1");
    u1.setName("Paul");

    JsonNode result = mapper.valueToTree(u1);

    assertEquals(expected, result);
  }
コード例 #3
0
  @Test
  public void testSaveSingleObjectWithNoTypeAndOneContainment() {
    JsonNode expected =
        mapper
            .createObjectNode()
            .put("userId", "1")
            .put("name", "Paul")
            .set("address", mapper.createObjectNode().put("addId", "a1").put("city", "Prague"));

    User u1 = ModelFactory.eINSTANCE.createUser();
    u1.setUserId("1");
    u1.setName("Paul");

    Address add = ModelFactory.eINSTANCE.createAddress();
    add.setAddId("a1");
    add.setCity("Prague");

    u1.setAddress(add);

    JsonNode result = mapper.valueToTree(u1);

    assertEquals(expected, result);
  }