Search in sources :

Example 1 with Person

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

the class JSONDeserializerTest method testArrayType.

@Test
public void testArrayType() {
    Person igor = creator.createJodder();
    Person modesty = creator.createModesty();
    Group group = new Group("brothers", igor, modesty);
    String json = new JsonSerializer().include("people").exclude("*.class").serialize(group);
    Group bro = new JsonParser().map(Group.class).parse(json);
    assertNotNull(bro);
    assertEquals("brothers", bro.getGroupName());
    assertEquals(2, bro.getPeople().length);
    assertEquals("Igor", bro.getPeople()[0].getFirstname());
    assertEquals("Modesty", bro.getPeople()[1].getFirstname());
}
Also used : Group(jodd.json.mock.Group) DateJsonSerializer(jodd.json.impl.DateJsonSerializer) Person(jodd.json.mock.Person) Test(org.junit.Test)

Example 2 with Person

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

the class JSONDeserializerTest method testListSerialization.

@Test
public void testListSerialization() {
    JoddJson.classMetadataName = "class";
    Person modesty = creator.createModesty();
    Person igor = creator.createJodder();
    Person pedro = creator.createPedro();
    List<Person> list = new ArrayList<>(3);
    list.add(modesty);
    list.add(igor);
    list.add(pedro);
    String json = new JsonSerializer().serialize(list);
    List<Person> people = new JsonParser().parse(json);
    assertEquals(ArrayList.class, people.getClass());
    json = new JsonSerializer().exclude("*.class").serialize(list);
    people = new JsonParser().map("values", Person.class).parse(json);
    assertEquals(ArrayList.class, people.getClass());
    assertEquals(3, people.size());
    assertEquals(Person.class, people.get(0).getClass());
    List<Map> peopleMap = new JsonParser().parse(json);
    assertEquals(ArrayList.class, peopleMap.getClass());
    assertEquals(3, peopleMap.size());
    assertEquals(HashMap.class, peopleMap.get(0).getClass());
}
Also used : ArrayList(java.util.ArrayList) DateJsonSerializer(jodd.json.impl.DateJsonSerializer) Person(jodd.json.mock.Person) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with Person

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

the class JSONDeserializerTest method testSubClassDeserialize.

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

Example 4 with Person

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

the class JSONDeserializerTest method testListDeserializationNoClass2.

@Test
public void testListDeserializationNoClass2() {
    Person modesty = creator.createModesty();
    Person igor = creator.createJodder();
    Person pedro = creator.createPedro();
    List<Person> list = new ArrayList<>(3);
    list.add(modesty);
    list.add(igor);
    list.add(pedro);
    String json = new JsonSerializer().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());
}
Also used : ArrayList(java.util.ArrayList) DateJsonSerializer(jodd.json.impl.DateJsonSerializer) Person(jodd.json.mock.Person) Test(org.junit.Test)

Example 5 with Person

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

the class JSONSerializationTest method setUp.

@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();
    people.add(jodder);
    people.add(modesty);
    people.add(pedro);
    dilbert = dataCreator.createDilbert();
    network = dataCreator.createNetwork("My Network", jodder, modesty);
}
Also used : Zipcode(jodd.json.mock.Zipcode) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Person(jodd.json.mock.Person) Before(org.junit.Before)

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