Search in sources :

Example 6 with Person

use of jodd.json.mock.Person in project jodd by oblac.

the class DataCreator method createJodder.

public Person createJodder() {
    Address home = new Address("173 Hackers Drive", "New York", "NY", new Zipcode("123123"));
    Address work = new Address("42 Computer Center", "Earth", "Milkiway", new Zipcode("42"));
    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;
}
Also used : Address(jodd.json.mock.Address) Phone(jodd.json.mock.Phone) Calendar(java.util.Calendar) Zipcode(jodd.json.mock.Zipcode) Person(jodd.json.mock.Person) Timestamp(java.sql.Timestamp)

Example 7 with Person

use of jodd.json.mock.Person in project jodd by oblac.

the class DataCreator method createPedro.

public Person createPedro() {
    Zipcode pedroZip = new Zipcode("848485");
    Address pedroHome = new Address("12 Acrelèndia Way", "Rio de Janeiro", "Brazil", pedroZip);
    Address pedroWork = new Address("12 Acrelèndia Way", "Rio de Janeiro", "Brazil", pedroZip);
    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;
}
Also used : Address(jodd.json.mock.Address) Phone(jodd.json.mock.Phone) Calendar(java.util.Calendar) Zipcode(jodd.json.mock.Zipcode) Person(jodd.json.mock.Person)

Example 8 with Person

use of jodd.json.mock.Person in project jodd by oblac.

the class DataCreator method createModesty.

public Person createModesty() {
    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;
}
Also used : Address(jodd.json.mock.Address) Calendar(java.util.Calendar) Zipcode(jodd.json.mock.Zipcode) Person(jodd.json.mock.Person) Timestamp(java.sql.Timestamp)

Example 9 with Person

use of jodd.json.mock.Person in project jodd by oblac.

the class JSONDeserializerTest method testDeserializeWithPath.

@Test
public void testDeserializeWithPath() {
    Person igor = creator.createJodder();
    Map map = new HashMap();
    map.put("person", igor);
    String json = new JsonSerializer().serialize(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());
}
Also used : HashMap(java.util.HashMap) DateJsonSerializer(jodd.json.impl.DateJsonSerializer) Person(jodd.json.mock.Person) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with Person

use of jodd.json.mock.Person in project jodd by oblac.

the class JSONDeserializerTest method testDeserializeNoIncludes.

@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());
}
Also used : DateJsonSerializer(jodd.json.impl.DateJsonSerializer) Person(jodd.json.mock.Person) Test(org.junit.Test)

Aggregations

Person (jodd.json.mock.Person)19 Test (org.junit.Test)15 DateJsonSerializer (jodd.json.impl.DateJsonSerializer)11 Address (jodd.json.mock.Address)5 Zipcode (jodd.json.mock.Zipcode)5 ArrayList (java.util.ArrayList)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 Phone (jodd.json.mock.Phone)3 Timestamp (java.sql.Timestamp)2 Map (java.util.Map)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ObjectJsonSerializer (jodd.json.impl.ObjectJsonSerializer)2 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Employee (jodd.json.mock.Employee)1 Group (jodd.json.mock.Group)1 Before (org.junit.Before)1