Package jodd.json.mock

Examples of jodd.json.mock.Person


  @Before
  @SuppressWarnings({"unchecked"})
  public void setUp() {
    DataCreator dataCreator = new DataCreator();
    pedroZip = new Zipcode("848485");
    Person pedro = dataCreator.createPedro();
    jodder = dataCreator.createJodder();
    modesty = dataCreator.createModesty();
    colors = dataCreator.createColorMap();

    people = new ArrayList();
View Full Code Here


    Phone pagerPhone = new Phone(PhoneNumberType.PAGER, "123 555-1234");
    Phone cellPhone = new Phone(PhoneNumberType.MOBILE, "770 777 5432");

    Calendar cal = Calendar.getInstance();
    cal.set(1988, Calendar.NOVEMBER, 23, 8, 11);
    Person charlie = new Person("Igor", "Spasic", cal.getTime(), home, work);
    cal = Calendar.getInstance();
    cal.set(1993, Calendar.JUNE, 6, 8, 11);
    charlie.setFirstBaseBallGame(new Timestamp(cal.getTime().getTime()));
    charlie.getPhones().add(pagerPhone);
    charlie.getPhones().add(cellPhone);

    charlie.getHobbies().add("read");
    charlie.getHobbies().add("run");
    charlie.getHobbies().add("code");

    return charlie;
  }
View Full Code Here

    Address benhome = new Address("NN Island", "Blue Cave", "ta", new Zipcode("82742"));
    Address benwork = new Address("44 Planetary St.", "Neptune", "Milkiway", new Zipcode("12345"));

    Calendar benCal = Calendar.getInstance();
    benCal.set(1986, Calendar.AUGUST, 8, 8, 11);
    Person ben = new Person("Modesty", "Blase", benCal.getTime(), benhome, benwork);
    benCal = Calendar.getInstance();
    benCal.set(1995, Calendar.MAY, 21, 8, 11);
    ben.setFirstBaseBallGame(new Timestamp(benCal.getTime().getTime()));
    ben.getHobbies().add("sneak");
    ben.getHobbies().add("kill");
    ben.getHobbies().add("fight");

    return ben;
  }
View Full Code Here

    Phone pedroPhone = new Phone(PhoneNumberType.MOBILE, "123 555 2323");

    Calendar pedroCal = Calendar.getInstance();
    pedroCal.set(1980, Calendar.APRIL, 12, 11, 45);
    Person pedro = new Person("Pedro", "Sanchez", pedroCal.getTime(), pedroHome, pedroWork);
    pedro.getPhones().add(pedroPhone);

    return pedro;
  }
View Full Code Here

    JoddJson.classMetadataName = null;
  }

  @Test
  public void testDeserializeNoIncludes() {
    Person jodder = creator.createJodder();
    String json = new JsonSerializer().serialize(jodder);
    Person jsonJodder = new JsonParser().parse(json, Person.class);

    assertNotNull(jsonJodder);

    assertEquals(jodder.getLastname(), jsonJodder.getLastname());
    assertEquals(jodder.getFirstname(), jsonJodder.getFirstname());
    assertEquals(jodder.getBirthdate(), jsonJodder.getBirthdate());

    assertEquals(jodder.getHome().getState(), jsonJodder.getHome().getState());
    assertEquals(jodder.getHome().getStreet(), jsonJodder.getHome().getStreet());
    assertEquals(jodder.getHome().getCity(), jsonJodder.getHome().getCity());

    assertEquals(jodder.getWork().getCity(), jsonJodder.getWork().getCity());

    assertEquals(jsonJodder, jsonJodder.getWork().getPerson());

    assertEquals(0, jsonJodder.getHobbies().size());
  }
View Full Code Here

    assertEquals(0, jsonJodder.getHobbies().size());
  }

  @Test
  public void testDeserializeWithPath() {
    Person igor = creator.createJodder();
    Map map = new HashMap();
    map.put("person", igor);

    String json = new JsonSerializer().serialize(map);

    map = (Map) new JsonParser().map("values", Person.class).parse(json);
    Person jsonIgor = (Person) map.get("person");

    assertNotNull(jsonIgor);

    assertEquals(igor.getLastname(), jsonIgor.getLastname());
    assertEquals(igor.getFirstname(), jsonIgor.getFirstname());
    assertEquals(igor.getBirthdate(), jsonIgor.getBirthdate());

    assertEquals(igor.getHome().getState(), jsonIgor.getHome().getState());
    assertEquals(igor.getHome().getStreet(), jsonIgor.getHome().getStreet());
    assertEquals(igor.getHome().getCity(), jsonIgor.getHome().getCity());

    assertEquals(igor.getWork().getCity(), jsonIgor.getWork().getCity());

    assertEquals(jsonIgor, jsonIgor.getWork().getPerson());
  }
View Full Code Here

    assertEquals(jsonIgor, jsonIgor.getWork().getPerson());
  }

  @Test
  public void testDeserializeWithIncludes() {
    Person igor = creator.createJodder();
    String json = new JsonSerializer().include("phones", "hobbies").serialize(igor);
    Person jsonIgor = new JsonParser().parse(json, Person.class);

    assertEquals(2, jsonIgor.getPhones().size());
    assertEquals(3, jsonIgor.getHobbies().size());
    assertEquals("run", jsonIgor.getHobbies().get(1));
  }
View Full Code Here

  @Test
  public void testSubClassDeserialize() {
    Employee dilbert = creator.createDilbert();

    String json = new JsonSerializer().include("phones", "hobbies").serialize(dilbert);
    Person jsonDilbert = new JsonParser().parse(json, Employee.class);

    assertNotNull(jsonDilbert);
    assertTrue(jsonDilbert instanceof Employee);
    assertEquals(dilbert.getCompany(), ((Employee) jsonDilbert).getCompany());
  }
View Full Code Here

  @Test
  public void testListSerialization() {
    JoddJson.classMetadataName = "class";

    Person modesty = creator.createModesty();
    Person igor = creator.createJodder();
    Person pedro = creator.createPedro();
    List<Person> list = new ArrayList<Person>(3);
    list.add(modesty);
    list.add(igor);
    list.add(pedro);
View Full Code Here

  @Test
  public void testListDeserializationNoClass() {
    JoddJson.classMetadataName = "class";

    Person modesty = creator.createModesty();
    Person igor = creator.createJodder();
    Person pedro = creator.createPedro();
    List<Person> list = new ArrayList<Person>(3);
    list.add(modesty);
    list.add(igor);
    list.add(pedro);

    String json = new JsonSerializer().exclude("*.class").serialize(list);
    List<Person> people = new JsonParser()
        .map("values", Person.class).parse(json);
    assertEquals(ArrayList.class, people.getClass());
    assertEquals(3, list.size());
    assertEquals(modesty.getFirstname(), list.get(0).getFirstname());
    assertEquals(igor.getFirstname(), list.get(1).getFirstname());
    assertEquals(pedro.getFirstname(), list.get(2).getFirstname());
  }
View Full Code Here

TOP

Related Classes of jodd.json.mock.Person

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.