Search in sources :

Example 6 with JsonNull

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());
}
Also used : JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) JsonNull(elemental.json.JsonNull) Test(org.junit.Test)

Example 7 with JsonNull

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());
}
Also used : JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) JsonNull(elemental.json.JsonNull) Test(org.junit.Test)

Example 8 with JsonNull

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);
}
Also used : JsonValue(elemental.json.JsonValue) JsonNull(elemental.json.JsonNull) Test(org.junit.Test)

Aggregations

JsonNull (elemental.json.JsonNull)8 JsonValue (elemental.json.JsonValue)8 Test (org.junit.Test)6 JsonObject (elemental.json.JsonObject)5 JsonSerializable (com.vaadin.flow.component.JsonSerializable)1 StateNode (com.vaadin.flow.internal.StateNode)1 StateTree (com.vaadin.flow.internal.StateTree)1 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)1 JsonBoolean (elemental.json.JsonBoolean)1 JsonString (elemental.json.JsonString)1 JsonType (elemental.json.JsonType)1 BeanInfo (java.beans.BeanInfo)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 Method (java.lang.reflect.Method)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 HashMap (java.util.HashMap)1 Logger (org.slf4j.Logger)1