use of jodd.json.mock.Person in project jodd by oblac.
the class JSONDeserializerTest method testArray.
@Test
public void testArray() {
Person[] p = new Person[3];
p[0] = creator.createJodder();
p[1] = creator.createDilbert();
p[2] = creator.createModesty();
String json = new JsonSerializer().serialize(p);
Person[] jsonP = new JsonParser().parse(json, Person[].class);
assertEquals(3, jsonP.length);
assertEquals("Igor", jsonP[0].getFirstname());
assertEquals("Dilbert", jsonP[1].getFirstname());
assertEquals("Modesty", jsonP[2].getFirstname());
}
use of jodd.json.mock.Person in project jodd by oblac.
the class JSONSerializationTest method testCopyOnWriteList.
@Test
public void testCopyOnWriteList() {
CopyOnWriteArrayList<Person> people = new CopyOnWriteArrayList<>();
people.add(jodder);
people.add(modesty);
String json = new JsonSerializer().serialize(people);
assertAttribute("firstname", json);
assertStringValue("Igor", json);
assertStringValue("Modesty", json);
}
use of jodd.json.mock.Person in project jodd by oblac.
the class JSONSerializationTest method testObject.
@Test
public void testObject() {
JoddJson.classMetadataName = "class";
JsonSerializer serializer = new JsonSerializer();
String jodderJson = serializer.serialize(jodder);
assertStringValue(Person.class.getName(), jodderJson);
assertAttribute("firstname", jodderJson);
assertStringValue("Igor", jodderJson);
assertAttribute("lastname", jodderJson);
assertStringValue("Spasic", jodderJson);
assertAttribute("work", jodderJson);
assertAttribute("home", jodderJson);
assertAttribute("street", jodderJson);
assertStringValue(Address.class.getName(), jodderJson);
assertAttribute("zipcode", jodderJson);
assertStringValue(Zipcode.class.getName(), jodderJson);
assertAttributeMissing("person", jodderJson);
assertAttributeMissing("phones", jodderJson);
assertStringValueMissing(Phone.class.getName(), jodderJson);
assertAttributeMissing("hobbies", jodderJson);
JsonSerializer jdrSerializer = new JsonSerializer();
jdrSerializer.exclude("home", "work");
String modestyJson = jdrSerializer.serialize(modesty);
assertStringValue(Person.class.getName(), modestyJson);
assertAttribute("firstname", modestyJson);
assertStringValue("Modesty", modestyJson);
assertAttribute("lastname", modestyJson);
assertStringValue("Blase", modestyJson);
assertAttribute("birthdate", modestyJson);
assertStringValueMissing(Address.class.getName(), modestyJson);
assertAttributeMissing("work", modestyJson);
assertAttributeMissing("home", modestyJson);
assertAttributeMissing("street", modestyJson);
assertAttributeMissing("city", modestyJson);
assertAttributeMissing("state", modestyJson);
assertStringValueMissing(Zipcode.class.getName(), modestyJson);
assertAttributeMissing("zipcode", modestyJson);
assertStringValueMissing(Phone.class.getName(), modestyJson);
assertAttributeMissing("hobbies", modestyJson);
assertAttributeMissing("person", modestyJson);
serializer.exclude("home.zipcode", "work.zipcode");
String json2 = serializer.serialize(jodder);
assertStringValue(Person.class.getName(), json2);
assertAttribute("work", json2);
assertAttribute("home", json2);
assertAttribute("street", json2);
assertStringValue(Address.class.getName(), json2);
assertAttributeMissing("zipcode", json2);
assertAttributeMissing("phones", json2);
assertStringValueMissing(Zipcode.class.getName(), json2);
assertStringValueMissing(Phone.class.getName(), json2);
assertAttributeMissing("hobbies", json2);
assertAttributeMissing("type", json2);
assertStringValueMissing("PAGER", json2);
serializer.include("hobbies").exclude(true, "phones.areaCode", "phones.exchange", "phones.number");
String json3 = serializer.serialize(jodder);
assertStringValue(Person.class.getName(), json3);
assertAttribute("work", json3);
assertAttribute("home", json3);
assertAttribute("street", json3);
assertStringValue(Address.class.getName(), json3);
assertAttribute("phones", json3);
assertAttribute("phoneNumber", json3);
assertStringValue(Phone.class.getName(), json3);
assertAttribute("hobbies", json3);
assertAttributeMissing("zipcode", json3);
assertAttributeMissing(Zipcode.class.getName(), json3);
assertAttributeMissing("areaCode", json3);
assertAttributeMissing("exchange", json3);
assertAttributeMissing("number", json3);
assertAttribute("type", json3);
assertStringValue("PAGER", json3);
assertTrue(json3.startsWith("{"));
assertTrue(json3.endsWith("}"));
}
use of jodd.json.mock.Person in project jodd by oblac.
the class JSONDeserializerTest method testListDeserializationNoClass.
@Test
public void testListDeserializationNoClass() {
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().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());
}
Aggregations