use of elemental.json.JsonNull in project flow by vaadin.
the class JsonSerializerTest method serializeEmptyObjectWithBasicCollections_returnJsonObjectWithNullProperties.
@Test
public void serializeEmptyObjectWithBasicCollections_returnJsonObjectWithNullProperties() {
ObjectWithBasicCollections bean = new ObjectWithBasicCollections();
/*
* private List<String> listOfStrings; private Set<Integer>
* setOfIntegers; private LinkedList<Boolean> linkedListOfBooleans;
* private ArrayList<Double> arrayListOfDoubles;
*
*/
JsonValue json = JsonSerializer.toJson(bean);
Assert.assertTrue("The JsonValue should be instanceof JsonObject", json instanceof JsonObject);
JsonObject jsonObject = (JsonObject) json;
Assert.assertTrue(jsonObject.hasKey("listOfStrings"));
Assert.assertTrue(jsonObject.get("listOfStrings") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("setOfIntegers"));
Assert.assertTrue(jsonObject.get("setOfIntegers") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("linkedListOfBooleans"));
Assert.assertTrue(jsonObject.get("linkedListOfBooleans") instanceof JsonNull);
Assert.assertTrue(jsonObject.hasKey("arrayListOfDoubles"));
Assert.assertTrue(jsonObject.get("arrayListOfDoubles") instanceof JsonNull);
bean = JsonSerializer.toObject(ObjectWithBasicCollections.class, json);
Assert.assertNotNull("The deserialized object should not be null", bean);
Assert.assertNull(bean.getListOfStrings());
Assert.assertNull(bean.getSetOfIntegers());
Assert.assertNull(bean.getLinkedListOfBooleans());
Assert.assertNull(bean.getArrayListOfDoubles());
}
use of elemental.json.JsonNull in project flow by vaadin.
the class JsonSerializerTest method serializeEmptyRecursiveObject_returnJsonObjectWithNullProperties.
@Test
public void serializeEmptyRecursiveObject_returnJsonObjectWithNullProperties() {
RecursiveObject bean = new RecursiveObject();
JsonValue json = JsonSerializer.toJson(bean);
Assert.assertTrue("The JsonValue should be instanceof JsonObject", json instanceof JsonObject);
JsonObject jsonObject = (JsonObject) json;
Assert.assertTrue(jsonObject.hasKey("recursive"));
Assert.assertTrue(jsonObject.get("recursive") instanceof JsonNull);
Assert.assertEquals(0, jsonObject.getNumber("index"), PRECISION);
bean = JsonSerializer.toObject(RecursiveObject.class, json);
Assert.assertNotNull("The deserialized object should not be null", bean);
Assert.assertNull(bean.getRecursive());
Assert.assertEquals(0, bean.getIndex());
}
use of elemental.json.JsonNull in project flow by vaadin.
the class JsonSerializerTest method serializeNull_returnNull.
@Test
public void serializeNull_returnNull() {
JsonValue json = JsonSerializer.toJson((Object) null);
Assert.assertTrue("The JsonValue should be instanceof JsonNull", json instanceof JsonNull);
}
Aggregations