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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations