Search in sources :

Example 1 with JsonBoolean

use of elemental.json.JsonBoolean in project flow by vaadin.

the class JsonSerializerTest method serializeBasicTypes_returnJsonBasicTypes.

@Test
public void serializeBasicTypes_returnJsonBasicTypes() {
    JsonValue json = JsonSerializer.toJson("someString");
    Assert.assertTrue("The JsonValue should be instanceof JsonString", json instanceof JsonString);
    Assert.assertEquals("someString", json.asString());
    json = JsonSerializer.toJson(0);
    Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
    Assert.assertEquals(0.0, json.asNumber(), PRECISION);
    json = JsonSerializer.toJson(0.0);
    Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
    Assert.assertEquals(0.0, json.asNumber(), PRECISION);
    json = JsonSerializer.toJson(0l);
    Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
    Assert.assertEquals(0.0, json.asNumber(), PRECISION);
    json = JsonSerializer.toJson((byte) 0);
    Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
    Assert.assertEquals(0.0, json.asNumber(), PRECISION);
    json = JsonSerializer.toJson((short) 0);
    Assert.assertTrue("The JsonValue should be instanceof JsonNumber", json instanceof JsonNumber);
    Assert.assertEquals(0.0, json.asNumber(), PRECISION);
    json = JsonSerializer.toJson(true);
    Assert.assertTrue("The JsonValue should be instanceof JsonBoolean", json instanceof JsonBoolean);
    Assert.assertTrue(json.asBoolean());
    json = JsonSerializer.toJson(false);
    Assert.assertTrue("The JsonValue should be instanceof JsonBoolean", json instanceof JsonBoolean);
    Assert.assertFalse(json.asBoolean());
    json = JsonSerializer.toJson(SomeEnum.SOME_VALUE_1);
    Assert.assertTrue("The JsonValue should be instanceof JsonString", json instanceof JsonString);
    Assert.assertEquals(SomeEnum.SOME_VALUE_1.name(), json.asString());
}
Also used : JsonNumber(elemental.json.JsonNumber) JsonValue(elemental.json.JsonValue) JsonBoolean(elemental.json.JsonBoolean) JsonString(elemental.json.JsonString) Test(org.junit.Test)

Example 2 with JsonBoolean

use of elemental.json.JsonBoolean in project flow by vaadin.

the class JsonCodecTest method decodeAs_booleanJson.

@Test
public void decodeAs_booleanJson() {
    JsonBoolean json = Json.create(true);
    Assert.assertTrue(JsonCodec.decodeAs(json, Boolean.class));
    Assert.assertEquals("true", JsonCodec.decodeAs(json, String.class));
    Assert.assertEquals(Integer.valueOf(1), JsonCodec.decodeAs(json, Integer.class));
    Assert.assertEquals(Double.valueOf(1.0), JsonCodec.decodeAs(json, Double.class));
    Assert.assertEquals(json, JsonCodec.decodeAs(json, JsonValue.class));
}
Also used : JsonValue(elemental.json.JsonValue) JsonBoolean(elemental.json.JsonBoolean) JsonString(elemental.json.JsonString) JsonBoolean(elemental.json.JsonBoolean) Test(org.junit.Test)

Aggregations

JsonBoolean (elemental.json.JsonBoolean)2 JsonString (elemental.json.JsonString)2 JsonValue (elemental.json.JsonValue)2 Test (org.junit.Test)2 JsonNumber (elemental.json.JsonNumber)1